2011-01-25 14 views
14

jak dodać jeden układ w innym układzie.Zostałem utworzony ten układ w tblrow.XML.so chcę dodać te wiersze w menu.XML.i chcesz dodać te wiersze w zależności od nie wiersze.Jak mogę to zrobić.Jeśli dodaję, jak mogę zidentyfikować każdy wiersz.Proszę pomóc mi.Musię rozwiązania w java nie w XML. Mój kod tododawanie układu w innym układzie

<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>   

.

Odpowiedz

26

Możesz dołączyć jeden plik układu do innego, a tę technikę nazywa się ponownym użyciem układów Androida przy użyciu znacznika include. przykład:

<include android:id="@+id/myid1" layout="@layout/workspace_screen" /> 

ta jest wyjaśniona w a blogpost by Android developers..

Jeszcze jeden artykuł na temat Android developer site explains the layout re-usability.

+0

wiem this.but trzeba go w kodzie Java. –

+0

To może ci pomóc. http://stackoverflow.com/questions/3195668/android-programmatically-include-layout-i-without-xml – Gopinath

4

utworzyć plik 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> 

W układzie głównym:

<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> 
Powiązane problemy