I have a GridLayout
with 16 dots, which are ImageViews
created from ShapeDrawables
. How can I set the color of these without creating a new ShapeDrawable
?
Here's most of my code:
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);
This is run in the onCreate()
, and I wish to change the lines marked above to change the color of the views instead of the alpha. I know this is possible if I replace the view with a new view, but is there a better way to do this?
This is a picture of the dot grid: