android布局隐藏了,Android中10秒后隐藏布局?

使用Handler & Runnable 。

您可以使用postDelayed of Handler延迟Runnable。

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 } };

现在在onButtonClick事件中,您必须告诉Handler在X毫秒后运行runnable:

mHandler.postDelayed(mRunnable,10*1000);

如果要取消它,则必须使用mHandler.removeCallbacks(mRunnable);

更新(根据编辑的问题)您只需要使用removeCallbacks()从Handler删除回调

所以只需在onTouch方法中更新代码,如下所示:

mVolLayout.setVisibility(View.VISIBLE); mVolHandler.removeCallbacks(mVolRunnable); mVolHandler.postDelayed(mVolRunnable, 10000);

您可以使用单击按钮时启动的animation ,持续时间为10秒,淡出布局,并可能在最后将其可见性设置为GONE 。

以下代码会在3秒内隐藏您的布局。 您可以通过更改此处为延迟更改的常量来更改时间。

private void HideLayout() { final View view=volume_control_layout; view.postDelayed(new Runnable() { public void run() { if(!volume_controller.isPressed()) { view.setVisibility(View.INVISIBLE); } else { HideLayout(); } } }, 3000); // (3000 == 3secs) }

使用处理程序在10秒后隐藏布局。 使用Post延迟方法

public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); pd=ProgressDialog.show(this,"","Loading, Please wait .. ",true); setTitle("set title"); final Handler uiThreadCallback=new Handler(); final Runnable runInUIThread= new Runnable(){ public void run(){ fnDraw(); pd.dismiss(); } }; new Thread(){ @Override public void run(){ uiThreadCallback.post(runInUIThread); } }.start(); } public void fnDraw(){ setContentView(R.layout.define ur xml if any); i1=(ImageView)findViewById(R.id.i1); t1=(TextView)findViewById(R.id.t1); t2=(TextView)findViewById(R.id.t2); timerRegister=new Timer(); lIteration=0; checkTime=new TimerTask(){ public void run(){ if(lIteration==1){ timerRegister.cancel(); uiDrawThreadCallback.post(runInUIDrawThread); } lIteration++; return; } }; timerRegister.scheduleAtFixedRate(checkTime,0,10000); } final Handler uiDrawThreadCallback=new Handler(); final Runnable runInUIDrawThread= new Runnable(){ @Override public void run(){ fnDrawAgain(); } }; public void fnDrawAgain(){ Intent intent=new Intent(this,new class you want to open.class); startActivity(intent); }

}

尝试它,确保它将在你的创建屏幕上工作

以上都不是好的解决方案。 想象一下,视图在10秒后不可见(例如:它向下滚动),因此Visibility.GONE将无法使用它。 我仍在寻找解决方案

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值