Hide A Layout After 10 Seconds In Android?
Make use of Handler
& Runnable
.
You can delay a Runnable using postDelayed
of Handler.
Runnable mRunnable;
Handler mHandler=new Handler();
mRunnable=new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
yourLayoutObject.setVisibility(View.INVISIBLE); //If you want just hide the View. But it will retain space occupied by the View.
yourLayoutObject.setVisibility(View.GONE); //This will remove the View. and free s the space occupied by the View
}
};
Now inside onButtonClick event you have to tell Handler to run a runnable after X milli seconds:
mHandler.postDelayed(mRunnable,10*1000);
If you want to cancel this then you have to use mHandler.removeCallbacks(mRunnable);
Update (According to edited question)
You just need to remove callbacks from Handler
using removeCallbacks()
So just update your code inside onTouch
method like this :
mVolLayout.setVisibility(View.VISIBLE);
mVolHandler.removeCallbacks(mVolRunnable);
mVolHandler.postDelayed(mVolRunnable, 10000);
You can use an Animation started when you click the button, with 10 seconds duration that fades out the layout and probably sets its visibility to GONE
at the end.