我正在开发屏幕,其中四个按钮从左向右水平移动,并且在每个按钮上单击我必须打开webView,这样任何人都可以建议如何更改按钮位置,以便检测到按钮的单击事件。
我已经读过:动画实际上不会移动按钮而只会移动其图像。 那么添加按钮的正确方法是什么。
我是stackoverflow和android动画的新手,所以请建议....
setContentView(R.layout.activity_main);
ll = (LinearLayout) findViewById(R.id.topbar);
animation = AnimationUtils.loadAnimation(this, R.anim.animation_right);
animation.setRepeatCount(TranslateAnimation.INFINITE);
animation.setRepeatMode(TranslateAnimation.RESTART);
animation.setAnimationListener(new SlidingButtonAnimationListener());
animation.setDuration(30000);
ll.startAnimation(animation);
button1=(Button)findViewById(R.id.button1);
button2=(Button)findViewById(R.id.button2);
button3=(Button)findViewById(R.id.button3);
button4=(Button)findViewById(R.id.button4);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d(TAG, "Button1 clicked");
}
});
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d(TAG, "Button2 clicked");
}
});
button3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d(TAG, "Button3 clicked");
}
});
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d(TAG, "Button4 clicked");
}
});
}
private class SlidingButtonAnimationListener implements AnimationListener {
public void onAnimationEnd(Animation animation){
}
public void onAnimationRepeat(Animation animation){}
public void onAnimationStart(Animation animation){}
}