res/animation/move.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="800" />
</set>
res/layout/activity_move.xml
<?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">
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher/>
<Button android:id="@+id/btn_Start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Animation/>
</RelativeLayout>
MainActivity.java
package example.animations;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity implements AnimationListener {
ImageView image;
Button btn_Start;
Animation animationMove;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_move);
image= (ImageView) findViewById(R.id.image);
btn_Start= (Button) findViewById(R.id.btn_Start);
animationRotate= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.move);
animationRotate.setAnimationListener(this);
btn_Start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
image.startAnimation(animationMove);
}
});
}
@Override
public void onAnimationEnd(Animation animation) {
if (animation == animationMove) {
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="800" />
</set>
res/layout/activity_move.xml
<?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">
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher/>
<Button android:id="@+id/btn_Start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Animation/>
</RelativeLayout>
MainActivity.java
package example.animations;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity implements AnimationListener {
ImageView image;
Button btn_Start;
Animation animationMove;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_move);
image= (ImageView) findViewById(R.id.image);
btn_Start= (Button) findViewById(R.id.btn_Start);
animationRotate= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.move);
animationRotate.setAnimationListener(this);
btn_Start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
image.startAnimation(animationMove);
}
});
}
@Override
public void onAnimationEnd(Animation animation) {
if (animation == animationMove) {
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
No comments:
Post a Comment