Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Button is not clickable after TranslateAnimation
- <?xml version="1.0" encoding="utf-8"?>
- <Button xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:text="Press to begin animation" />
- public class TestActivity extends Activity {
- public final String TAG="TestActivity";
- boolean toTop=false;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button b=(Button)findViewById(R.id.button);
- b.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- Toast.makeText(TestActivity.this, "left="+v.getLeft()+"nright="+v.getRight(), Toast.LENGTH_SHORT).show();
- Animation translateAnimation;
- if(toTop) translateAnimation=new TranslateAnimation(0, 0, 0, -100);
- else translateAnimation=new TranslateAnimation(0, 0, 0, 100);
- translateAnimation.setDuration(1000);
- translateAnimation.setFillEnabled(true);
- translateAnimation.setFillAfter(true);
- v.startAnimation(translateAnimation);
- toTop=!toTop;
- }
- });
- }
- }
- public class TestActivity extends Activity {
- public final String TAG="TestActivity";
- boolean toTop=false;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button b=(Button)findViewById(R.id.button);
- b.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- int modifierY;
- if(toTop) modifierY=-100;
- else modifierY=100;
- Animation translateAnimation=new TranslateAnimation(0, 0, 0, modifierY);
- translateAnimation.setDuration(1000);
- translateAnimation.setFillEnabled(true);
- MyAnimationListener listener=new MyAnimationListener(v, modifierY,TestActivity.this);
- translateAnimation.setAnimationListener(listener);
- v.startAnimation(translateAnimation);
- toTop=!toTop;
- }
- });
- }
- public class MyAnimationListener implements AnimationListener{
- View mView;
- int mModifier;
- Context mContext;
- public MyAnimationListener(View v, int modifier, Context c){
- mView=v;
- mModifier=modifier;
- mContext=c;
- }
- public void onAnimationEnd(Animation animation) {
- int[] pos={mView.getLeft(),mView.getTop()+mModifier,mView.getRight(),mView.getBottom()+mModifier};
- mView.layout(pos[0],pos[1],pos[2],pos[3]);
- Toast.makeText(mContext, "left="+mView.getLeft()+"ntop="+mView.getTop(), Toast.LENGTH_SHORT).show();
- }
- public void onAnimationRepeat(Animation animation) {}
- public void onAnimationStart(Animation animation) {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement