Android更改可见性不起作用

时间:2013-04-08 11:38:46

标签: android android-imageview runnable

简单的纸牌游戏设置创建行数和columns张数量:

    TableLayout tableCards = new TableLayout(this);
    RelativeLayout.LayoutParams relLayParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    relLayParams.addRule(RelativeLayout.CENTER_IN_PARENT);

    tableCards.setLayoutParams(relLayParams);

    int i = 0;
    StringBuilder sbCardsDebug = new StringBuilder('\n');
    for (int r = 0; r < rows; r++) {
        // create a new row
        TableRow tr = new TableRow(this);
        tr.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));

        for (int c = 0; c < columns; c++) {
            ImageView card = new ImageView(this);
            card.setTag("" + i);
            card.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));

            card.setImageDrawable(bitmapCardBackScaled);

            tr.addView(card);

            card.setOnClickListener(cardClickListener);

            i++;
        }

        // add the row:
        tableCards.addView(tr);

    }

    relativeLayoutCardsHolder.addView(tableCards);

在监听器的某个地方,我有一个像这样的代码部分:

                imageView.setVisibility(View.INVISIBLE);

imageView是卡片的地方(我设置断点也记录并显示正确的卡片。

问题:它不会变得不可见。

我想也许我不是一个好的线程,或者在设置隐形后我是否需要做一些事情?

我尝试过:

        imageView.post(new Runnable() {

            public void run() {
                imageView.setVisibility(View.INVISIBLE);
            }
        });

                TableLayout parent = (TableLayout) imageView.getParent().getParent();
                parent.invalidate();
                parent.requestLayout();

并没有成功。请提出任何建议,我没有想法,谢谢。

EDIT1:

作为建议我也试过postDelayed:

        imageView.postDelayed(new Runnable() {

            public void run() {
                imageView.setVisibility(View.INVISIBLE);
            }
        }, 600);

侦听器正在从第353行到第424行调用带有动画的几个类,传递引用,它将显示我的脏工作,也将显示业务逻辑(NDA agrement),您感兴趣的部分是什么? - 执行最少1000行。

1 个答案:

答案 0 :(得分:1)

如果它是一个正确的ImageView,它必须工作。

imageView.setAlpha(0);

希望它有所帮助。

相关问题