Android 隐藏LinearLayout

来源:互联网 发布:三星清零软件 编辑:程序博客网 时间:2024/05/18 17:01

     有这样的需求,所有的界面上方都有一个标题栏,有些界面需要需要、有些特殊的界面就不需要这个标题栏,需要显示其他的按钮,这个时候就要隐藏掉,切换界面之后就会重新显示,解决方案其实非常简单:

     1.在界面的布局文件xml中,将LinearLayout设置一个id,如下文件:

  <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" />
</LinearLayout>
2.在代码中找到这个布局的id并初始化,之后,使用visiable属性,对显示隐藏进行控制,如下:
@Overrideprotected 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);

}


      这样就可以搞定了,欢迎批评指教。

0 0
原创粉丝点击