私のコードにはいくつかの問題があります。
1. getX()、getY() を使用して、相対的なレイアウトでイメージビューの位置を取得しています。ポジションを取得する正しい方法はありますか?
2.Translate Animate は正確な位置で停止しません。つまり、画像ビュー (目的地) を横切ります。
3.アニメーションが特定の位置で終了する場合、背景画像をこの位置に設定したいのですが、どうすればそれを達成できますか?
- 連続アニメーションではロジックが間違っていますか? 私はアニメーション終了方法で使用しました..あなたの提案をしてください. 私は初心者です。これは私が開発している小さなゲームです。
ここに私のxmlとJavaコードがあります
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical" >
<ImageView
android:id="@+id/player4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:visibility="invisible"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/player6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:layout_toLeftOf="@+id/player5"
android:visibility="invisible"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/player5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="14dp"
android:layout_marginRight="89dp"
android:layout_toLeftOf="@+id/player4"
android:visibility="invisible"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/player3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/player5"
android:layout_marginRight="26dp"
android:layout_toLeftOf="@+id/player2"
android:visibility="invisible"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/player2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:visibility="invisible"
android:layout_marginRight="16dp"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/player1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/player2"
android:layout_alignParentTop="true"
android:visibility="invisible"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/player7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/player1"
android:layout_alignLeft="@+id/player6"
android:visibility="invisible"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/dealer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/player4"
android:layout_alignParentTop="true"
android:visibility="invisible"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
私の.javaファイル
//getting the imageviews from layout
player1=(ImageView)findViewById(R.id.player1);
player2=(ImageView)findViewById(R.id.player2);
player3=(ImageView)findViewById(R.id.player3);
player4=(ImageView)findViewById(R.id.player4);
player5=(ImageView)findViewById(R.id.player5);
player6=(ImageView)findViewById(R.id.player6);
player7=(ImageView)findViewById(R.id.player7);
dealer=(ImageView)findViewById(R.id.dealer);
private void Logic() {
// TODO Auto-generated method stub
if(players ==1)animation = new TranslateAnimation(0,addX.get(0),0,addY.get(0));
if(players ==2)animation = new TranslateAnimation(0,addX.get(1),0, addY.get(1));
if(players ==3)animation = new TranslateAnimation(0,addX.get(2),0, addY.get(2));
if(players ==4)animation = new TranslateAnimation(0,addX.get(3),0, addY.get(3));
if(players ==5)animation = new TranslateAnimation(0,addX.get(4),0, addY.get(4));
if(players ==6)animation = new TranslateAnimation(0,addX.get(5),0, addY.get(5));
if(players ==7)animation = new TranslateAnimation(0,addX.get(6),0, addY.get(6));
}
//Method for Start Animation
private void doAnimation() {
// TODO Auto-generated method stub
animation.setDuration(1000);
animation.setFillAfter( true );
animation.setAnimationListener(this);
dealer.startAnimation(animation);
}
//IN Animation END
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
dealer.clearAnimation();
dealer.setImageResource(R.drawable.singlecard);
players=players+1;
dealer.clearAnimation();
if(players<=count){
Logic();
doAnimation();
}
}