0

I'm trying to make three seperate bars "float" down the screen, but for some reason, only one is visible. Here is my code:

// initialized the bar
ShapeDrawable barShape = new ShapeDrawable(new RectShape());
barShape.getPaint().setColor(Color.CYAN);
barShape.setIntrinsicHeight(20);
barShape.setIntrinsicWidth(mDisplayWidth);

// defines an imageview with the bar in it
mBarView1 = new ImageView(getApplicationContext());
mBarView1.setImageDrawable(barShape);
mBarView1.setTranslationX(0);
mBarView1.setTranslationY(0);

// Copies the bars
mBarView2 = new ImageView(getApplicationContext());
mBarView2.setImageDrawable(barShape);

mBarView3 = new ImageView(getApplicationContext());
mBarView3.setImageDrawable(barShape);

// Adds the bars to the grid
((LinearLayout) findViewById(R.id.linear_layout)).addView(mBarView1);
((LinearLayout) findViewById(R.id.linear_layout)).addView(mBarView2);
((LinearLayout) findViewById(R.id.linear_layout)).addView(mBarView3);

mBarView2.setTranslationX(0);
mBarView2.setTranslationY(50);
mBarView3.setTranslationX(0);
mBarView3.setTranslationY(150);

// updates the gates every 10 milliseconds
final Handler h = new Handler();
final int delay = 10;//milli seconds

h.postDelayed(new Runnable() {
    public void run() {
        moveBars();
        h.postDelayed(this, delay);
    }
}, delay);

And here is my moveBars() method:

private void moveBars() {
    mBarView1.setTranslationY(mBarView1.getY() + 1);
    mBarView2.setTranslationY(mBarView2.getY() + 10);
    mBarView3.setTranslationY(mBarView3.getY() + 100);
}

I'm thinking it could be because they are referring to the same ShapeDrawable object, but if that's true, how do I fix that?

Onik
  • 19,396
  • 14
  • 68
  • 91
ElectronicGeek
  • 3,312
  • 2
  • 23
  • 35

0 Answers0