2011-07-14 127 views
1

是否可以在另一佈局內多次膨脹和移除佈局?我有一個主要佈局如下佈局中運行期間多次膨脹一個佈局

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> 

對此的任何建議將是偉大的..

回答

1

是我認爲你可以充氣一個佈局在另一個例如我多次向ViewFlipper添加視圖。這些視圖基本上是一個佈局,我膨脹,然後作爲一個孩子添加。這裏是例子:

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

現在你已經搶到的LinearLayout爲「ll_main」,現在你可以把它添加到所需的佈局作爲一個孩子。