I have a table row with two buttons, and I use animations to fade the entire table row out after a WebView has not been touched for three seconds. Once the WebView is touched, the table row fades back in. However, I noticed that while the table row is faded out (and the buttons are not visible), the buttons are still clickable. I've tried setting the table row visibility to View.GONE immediately following the fade out animation, and then setting the visibility to View.VISIBLE right before the fade in animation, to no avail; it just seemed to ignore when I set it to View.VISIBLE, because once the table row it disappeared it would not reappear at the screen touch;
TableRow tr;
Animation fade_in = new AlphaAnimation(0.0f, 1.0f);
Animation fade_out = new AlphaAnimation(1.0f, 0.0f);
WebView loss_source_dest;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.loss);
getStrings();
findIDs();
fade_in.setDuration(750);
fade_out.setDuration(750);
fade_out.setStartOffset(3000);
initial_fade.setDuration(750);
fade_in.setFillAfter(true);
fade_out.setFillAfter(true);
tr.startAnimation(fade_out);
loss_source_dest.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
tr.setVisibility(v.VISIBLE);
tr.startAnimation(fade_in);
tr.startAnimation(fade_out);
tr.setVisibility(v.GONE);
return false;
}
});
Ok, it seems like there's a few issues here.
1) To fix the buttons remaining clickable after setVisibility(View.GONE) has been called, there is a solution set out in this... android View with View.GONE still receives onTouch and onClick. (I've attempted to add this to your solution).
2) The startAnimation method call is non-blocking, so the best solution would be to use an AnimationListener that detects which animation has finished, and then sets the button's visibility to View.GONE.
TableRow tr;
Animation fade_in = new AlphaAnimation(0.0f, 1.0f);
Animation fade_out = new AlphaAnimation(1.0f, 0.0f);
WebView loss_source_dest;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.loss);
getStrings();
findIDs();
fade_in.setDuration(750);
fade_out.setDuration(750);
fade_out.setStartOffset(3000);
fade_out.setAnimationListener(new AnimationListener(){
public void onAnimationStart(Animation anim)
{
}
public void onAnimationRepeat(Animation anim)
{
}
public void onAnimationEnd(Animation anim)
{
tr.setVisibility(View.GONE);
}
});
initial_fade.setDuration(750);
// fade_in.setFillAfter(true); (Removed)
// fade_out.setFillAfter(true); (Removed)
tr.startAnimation(fade_out);
loss_source_dest.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
tr.setVisibility(v.VISIBLE);
tr.startAnimation(fade_in);
tr.startAnimation(fade_out);
return false;
}
});
I hope I have helped :)