I can move my imageView by animations but after moving the onclick method doesn't work.
If I clicked the old default position of the imageview the onClick method is invoked so how can I move the imageView permanently and the listeners work correct?
my code :
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;
}
}
}
ObjectAnimator was the correct way to completely move the imageview