Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
假设 D 是一个图像视图,它在 x 方向上从 0 移动到 200。请参阅下面的代码。
public class DActivity extends Activity { ImageView D; int x=0,y=0; int a=0; int newx=0; TranslateAnimation TA; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); D=(ImageView)findViewById(R.id.d); RelativeLayout RL=(RelativeLayout)findViewById(R.id.rl); D.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub x=v.getLeft(); y=v.getTop(); Toast.makeText(getApplicationContext(), "X="+x+"y="+y, Toast.LENGTH_LONG).show(); if(x==0){ D.setEnabled(false); a=200; newx=200; Anim(); } if(x==200){ D.setEnabled(false); a=-200; newx=0; Anim(); } return true; } }); } public void Anim(){ TranslateAnimation TAnimation=new TranslateAnimation(0, a, 0,0); TAnimation.setInterpolator(new LinearInterpolator()); TAnimation.setDuration(5000); TAnimation.setFillAfter(false); TAnimation.setFillEnabled(true); TAnimation.setFillBefore(true); D.startAnimation(TAnimation); TAnimation.setAnimationListener(new AnimationListener() { public void onAnimationStart(Animation animation) { } public void onAnimationRepeat(Animation animation) {} public void onAnimationEnd(Animation animation) { LayoutParams param=new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); param.setMargins(newx, y, 0, 0); D.setLayoutParams(param); D.setEnabled(true); } }); }
}
Suppose D is an imageview and its move from 0 to 200 in x direction.See below code.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(1)
假设 D 是一个图像视图,它在 x 方向上从 0 移动到 200。
请参阅下面的代码。
}
Suppose D is an imageview and its move from 0 to 200 in x direction.
See below code.
}