在GridLayout中更改ShapeDrawable ImageView的颜色

时间:2014-03-22 22:48:48

标签: android colors android-imageview android-gridlayout android-shapedrawable

我有一个GridLayout,其中有16个点,ImageViews来自ShapeDrawables。如何在不创建新ShapeDrawable的情况下设置这些颜色?

这是我的大部分代码:

for (int i = 0; i < dotNumWidth * dotNumWidth; i++) {
        ShapeDrawable redShape = new ShapeDrawable(new OvalShape());
        redShape.getPaint().setColor(Color.RED);
        redShape.setIntrinsicHeight(width / dotNumWidth - dotNumWidth * padding);
        redShape.setIntrinsicWidth(width / dotNumWidth - dotNumWidth * padding);

        // Put Cyan Shape into an ImageView
        ImageView redView = new ImageView(getApplicationContext());
        redView.setImageDrawable(redShape);
        redView.setPadding(padding, padding, padding, padding);

        grid.addView(redView);
    }

    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            grid.getChildAt(child).setAlpha(100); // I want to change this line

            child = (new Random()).nextInt(dotNumWidth * dotNumWidth);

            grid.getChildAt(child).setAlpha(0); // and this one

            handler.postDelayed(this, 1000);
        }
    }, 1000);

这是在onCreate()中运行的,我希望更改上面标记的行以更改视图的颜色而不是alpha。我知道如果我用新视图替换视图,这是可能的,但是有更好的方法吗?

这是点网格的图片:

enter image description here

0 个答案:

没有答案