伙计我可以通过动画移动我的imageView但移动onclick方法后无效 如果我单击了imageview的旧默认位置,则会调用onClick方法,那么如何永久移动imageView并使侦听器正常工作? 我的代码:
public class MainActivity extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* Remove title bar from transparent activity */
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
/* Define Views */
final ImageView keyboardIcon = (ImageView) findViewById(R.id.keyboardIcon);
final ImageView micIcon = (ImageView) findViewById(R.id.micIcon);
final RelativeLayout RL = (RelativeLayout) findViewById(R.id.activity_main);
final Animation moveMicIconRight = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.move_right);
final Animation moveKeyIconLeft = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.move_left);
micIcon.startAnimation(moveMicIconRight);
keyboardIcon.startAnimation(moveKeyIconLeft);
/* OnClick Listeners */
RL.setOnClickListener(this);
keyboardIcon.setOnClickListener(this);
micIcon.setOnClickListener(this);
/*-----------------*/
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.activity_main:
finish();
Toast.makeText(MainActivity.this, "Got it!", Toast.LENGTH_SHORT)
.show();
break;
case R.id.keyboardIcon:
Toast.makeText(MainActivity.this, "keyboard icon",
Toast.LENGTH_SHORT).show();
break;
case R.id.micIcon:
Toast.makeText(MainActivity.this, "mic icon", Toast.LENGTH_SHORT)
.show();
break;
}
}
}
答案 0 :(得分:0)
ObjectAnimator是完全移动imageview的正确方法