I have a button (placed in a linearlayout) with animation. After the animation is completed (simple translateAnimation) I want that animated button to be enabled. I realized that using an animation only has an effect for the button drawable, so the clickable “place” stays at the original position.
layout= (LinearLayout) findViewById (R.id.newitemtext);
layout.setBackgroundResource(R.drawable.white_box);
btn = (Button) findViewById (R.id.btn);
moveLefttoRight = new TranslateAnimation(0,0 , 0, 200);
moveLefttoRight.setDuration(1000);
moveLefttoRight.setFillAfter(true);
animbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
layout.startAnimation(moveLefttoRight);
layout.setEnabled(true);
}
});
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("TAG", "CCIK");
}
});
The btn button is in the LinearLayout layout. How could I set the position after the animation? I tried to use setPadding but with no success.
Thanks in advance!
Use
View.setLayoutParams(), to update a Views params – note that it depends on what kind of layout the view is inside as to how the params can be updated. For example, if your view is in aLinearLayout, then you will only be able to adjust params that relate to aLinearLayout(gravity, weight, width, height, etc.) so you would not be able to adjust the absolute X/Y coords. You may want to switch to something like aRelativeLayoutto try and move the view to the final destination based on the location of other views.