android - Translate animation with image view not getting position properly -


i have few issues in code:

1.i'm using getx(), gety() position of imageview in relative layout. correct method positions?

2.translate animate doesn't stop exact location.(i.e) crosses image view(destination)

3.if animation ends particular position want set background image position how can achieve that?

  1. is logic wrong in continuous animation? used in animation end method.. please provide suggestions. i'm beginner.this small game i'm developing.

here xml , java code

 <?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> 

my.java file

           //getting imageviews 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 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();      }     } 


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -