Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在运行期间,在布局内多次充气一个布局_Android_Android Layout - Fatal编程技术网

Android 在运行期间,在布局内多次充气一个布局

Android 在运行期间,在布局内多次充气一个布局,android,android-layout,Android,Android Layout,是否可以在另一个版面中多次充气和移除版面。我的主要布局如下所示 tab_bar.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingLef

是否可以在另一个版面中多次充气和移除版面。我的主要布局如下所示

tab_bar.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:paddingLeft="8dip"
  android:paddingRight="12dip"
  android:paddingTop="2dip"
  android:paddingBottom="1dip"
  android:background="@drawable/search_plate_browser" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
    <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      >
      <ImageButton android:id="@+id/arrow_left"
         android:background="@drawable/ic_back"
         android:layout_width="wrap_content"
         android:layout_height="30dip"
         android:gravity="center_vertical"
         android:visibility="gone"
      />
      <ImageButton android:id="@+id/arrow_right"
         android:background="@drawable/ic_forward"
         android:layout_width="wrap_content"
         android:layout_height="30dip"
         android:gravity="center_vertical"
         android:visibility="gone"
       />
    </LinearLayout>
    <ImageButton android:id="@+id/addtab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="4dip"
    android:paddingRight="4dip"
    android:paddingTop="4dip"
    android:paddingBottom="4dip"
    android:gravity="center_vertical"
    android:background ="@drawable/tabicon"
    />
</LinearLayout>

在此布局中,我需要在单击某些按钮时动态添加和删除下面的选项卡布局

tabview.xml

  <LinearLayout 
         android:layout_width="220dip"
         android:layout_height="35dip"
         android:orientation="horizontal"
         android:background="@drawable/browsertab_add">
      <ImageView
         android:id="@+id/favicon"
         android:layout_width="15dip"
         android:layout_height="15dip"
         android:layout_marginTop="10dip"
         android:layout_marginLeft="15dip"
         android:layout_marginRight="2dip" 
         android:layout_marginBottom="2dip"/>
     <TextView
         android:id="@+id/title"
         android:layout_height="match_parent"
         android:layout_width="140dip"
         android:layout_marginTop="10dip"
         android:layout_marginLeft="5dip"
         android:textAppearance="?android:attr/textAppearanceSmall"
         android:textColor="@color/white"
         android:scrollHorizontally="true"
         android:lines="1"
         android:singleLine="true" />
      <ImageButton
         android:id="@+id/close"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginLeft="8dip"
         android:gravity="left"
         android:background="@drawable/ic_tab_close" />
 </LinearLayout>


关于这方面的任何建议都将非常好。

是的,我认为您可以在另一个布局中膨胀一个布局,例如,我多次向我的ViewFlipper添加视图。这些视图基本上是一个布局,我将其放大,然后作为子视图添加。以下是一个例子:

LayoutInflater inflater = getLayoutInflater();
LinearLayout ll_main = (LinearLayout) inflater.inflate(R.layout.tabview,null); 

现在您已经将LinearLayout抓取为“ll_main”,现在您可以将其作为子级添加到所需的布局中。

不要删除它,只需将其可见性设置为Gone:)

有关该主题的一些链接:


尽管您也可以删除它们