2011-01-25 121 views
14

如何在另一個佈局中添加一個佈局。我在tblrow.XML.so中創建了此佈局,我想在menu.XML.i中添加此行,希望根據「 rows.If我可以做到這一點。如果我添加它,我如何識別每一行。請幫助我。我需要在java中的解決方案不在XML中。 我的代碼是在另一個佈局中添加布局

<TableRow android:id="@+id/tblRowMovies" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/btn_backgrnd" android:clickable="true" android:focusable = "true" android:layout_weight="1.0"> 
<ImageView android:layout_width="wrap_content" android:layout_height="fill_parent" android:src="@drawable/movie" android:layout_gravity="center_vertical|center_horizontal"/> 
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="MOVIES" android:layout_gravity="center_vertical" android:paddingLeft="20dp" android:textColor="@android:color/white" android:textSize="20sp" android:textStyle="bold"> 
</TextView>   

回答

4

創建文件titlebar.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width=」match_parent」 
    android:layout_height="wrap_content" 
    android:background="@color/titlebar_bg"> 

    <ImageView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/gafricalogo" /> 
</FrameLayout> 

在主要佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width=」match_parent」 
    android:layout_height=」match_parent」 
    android:background="@color/app_bg" 
    android:gravity="center_horizontal"> 

    <include layout="@layout/titlebar"/> 

    <TextView android:layout_width=」match_parent」 
       android:layout_height="wrap_content" 
       android:text="@string/hello" 
       android:padding="10dp" /> 

    ... 

</LinearLayout> 
相關問題