有这样的需求,所有的界面上方都有一个标题栏,有些界面需要需要、有些特殊的界面就不需要这个标题栏,需要显示其他的按钮,这个时候就要隐藏掉,切换界面之后就会重新显示,解决方案其实非常简单:
1.在界面的布局文件xml中,将LinearLayout设置一个id,如下文件:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25<LinearLayout android:id="@+id/user_status_bar" android:layout_width="fill_parent" android:layout_height="25dp" android:layout_marginTop="2dp" android:background="@color/statebg" android:orientation="horizontal" > <TextView android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="@string/trademargin" android:textColor="@color/white" android:textSize="12dp" /> <TextView android:id="@+id/price_trademargin" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:textColor="@color/white" android:textSize="12dp" />
复制代码
1</LinearLayout>
复制代码
12.在代码中找到这个布局的id并初始化,之后,使用visiable属性,对显示隐藏进行控制,如下:
复制代码
1
2
3
4
5
6
7
8
9
10
11@Override protected void initStatebarUI() { user_status_bar = (LinearLayout) this .findViewById(R.id.user_status_bar);if (fragmentKey == IBundleCommData.FRAGMENT_ID_About || fragmentKey == IBundleCommData.FRAGMENT_ID_Message || fragmentKey == IBundleCommData.FRAGMENT_ID_FOREIGN_NEWS || fragmentKey == IBundleCommData.FRAGMENT_ID_SelectInstrumentFragment || fragmentKey == IBundleCommData.FRAGMENT_ID_FOREIGN_NEWSCOMMENT) { hideUserStatus(View.GONE); } else { hideUserStatus(View.VISIBLE);
}
复制代码
1
这样就可以搞定了,欢迎批评指教。
最后
以上就是殷勤吐司最近收集整理的关于Android 隐藏LinearLayout的全部内容,更多相关Android内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复