I am creating a game and I have assigned three image views of (balls) at the top of my screen and code an animation for them. The balls are going down to the bottom from the top, but I want the balls from the top of the screen to not show at the start of the animation... any advice?
Here is the relevant Activity code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ball1 = (ImageView) findViewById(R.id.ball1);
ball2 = (ImageView) findViewById(R.id.ball2);
ball3 = (ImageView) findViewById(R.id.ball3);
}
private void startBallAnimation() {
final TranslateAnimation animation = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_PARENT, 0.0f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.0f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.0f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.86f
);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
mhandle.post(new Runnable() {
@Override
public void run() {
setBallColors();
}
});
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(final Animation animation) {}
}
}
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context="com.example.hp.colorspoof.MainActivity">
<!-- ball imageviews -->
<ImageView
android:id="@+id/ball1"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="left"
android:layout_marginLeft="40dp"
app:srcCompat="@drawable/ball_0" />
<ImageView
android:id="@+id/ball2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_horizontal"
app:srcCompat="@drawable/row2_2" />
<ImageView
android:id="@+id/ball3"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:layout_marginRight="40dp"
app:srcCompat="@drawable/row3_1" />
</FrameLayout>