标签:android android-button android-animation
伙计们我设计了视图,我在该视图中添加了三个按钮.我已经为所有三个按钮提供了on_click工具.我的要求是如果我点击button_1,则按钮_2和按钮3应该移动到新位置.但问题是,在将移动动画应用到button_2之后,button_3 on_click工具无法在新位置处理它们.
MainActivity.java
public class MainActivity extends Activity {
ImageButton slider,slidernew,sliderexisting;
boolean flag1 = true;
boolean flag2 = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//final LinearLayout container = (LinearLayout) findViewById(R.id.container);
slider = (ImageButton) findViewById(R.id.imageButton1);
slidernew = (ImageButton) findViewById(R.id.imageButton2);
sliderexisting = (ImageButton) findViewById(R.id.imageButton3);
// Set long default duration for the animator, for the purposes of this demo
//animate(slidernew).setDuration(2000);
slider.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/*int xValue = container.getWidth() - slidernew.getWidth();
int yValue = container.getHeight() - slidernew.getHeight();
animate(slidernew).x(xValue).y(yValue);*/
if(flag1==true)
{
animateSliderForward();
flag1=false;
}
else{
animateSliderBackward();
flag1=true;
}
}
});
slidernew.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(MainActivity.this,SecondActivity.class));
}
});
sliderexisting.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(MainActivity.this,SecondActivity.class));
}
});
}
void animateSliderForward(){
float fromX=0;
float toX=100;
float fromY=0;
float toY=100;
TranslateAnimation animation = new TranslateAnimation(fromX, toX, fromY, toY);
animation.setDuration(1000);
animation.setFillAfter(true);
float fromA=0;
float toA=-100;
float fromB=0;
float toB=100;
TranslateAnimation animation1 = new TranslateAnimation(fromA, toA, fromB, toB);
animation1.setDuration(1000);
animation1.setFillAfter(true);
slidernew.startAnimation(animation1);
sliderexisting.startAnimation(animation);
}
void animateSliderBackward(){
float fromX=100;
float toX=0;
float fromY=100;
float toY=0;
TranslateAnimation animation = new TranslateAnimation(fromX, toX, fromY, toY);
animation.setDuration(1000);
animation.setFillAfter(true);
float fromA=-100;
float toA=0;
float fromB=100;
float toB=0;
TranslateAnimation animation1 = new TranslateAnimation(fromA, toA, fromB, toB);
animation1.setDuration(1000);
animation1.setFillAfter(true);
slidernew.startAnimation(animation1);
sliderexisting.startAnimation(animation);
}
}
解决方法:
您已将onClickListener用于动画和移动到下一个活动.将一个更改为onTouchListener ..确保在onTouchListener中返回false,以便onClick执行
标签:android,android-button,android-animation 来源: https://codeday.me/bug/20190703/1361660.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。