2012-05-30 4 views
0

Я выполнил этот урок (http://developer.android.com/resources/tutorials/views/hello-tabwidget.html) и выполнил задачу, и все это работает нормально.Как добавить отдельные макеты под каждую вкладку с помощью TabLayout

Однако теперь я не уверен, как я могу добавить разные макеты под каждой вкладкой? должен добавить макет к main.xml и каким-то образом вызвать макет из созданных мной ячеек для каждой вкладки?

Я был бы очень признателен, если бы кто-нибудь посоветует мне об этом.

Например, я хочу добавить макет таблицы под одну из вкладок, как я могу это сделать?

Большое спасибо

ответ

0

See Этот пример является полезным Example of the TabLayout

модифицировал этот класс Androidactivity.java

public class AndroidActivity extends Activity { 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.androidtab); 

добавить этот xml файл в Res/layout/androidtab.xml

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/tableLayout1"  
android:layout_width="fill_parent" 
android:layout_height="fill_parent"  
android:gravity="top"  
android:stretchColumns="1"> 
<LinearLayout 
    android:id="@+id/top_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 
    <TextView 
     android:id="@+id/text" 
     android:textStyle="bold" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textSize="20dp" 
     android:text="Create Photo" /> 
</LinearLayout>  
<TextView    
     android:id="@+id/editUsername" 
     android:layout_width="fill_parent" 
     android:layout_height="40dp" 
     android:layout_weight="4" 
     android:text="CREATE NEW RECORD"    
     android:layout_marginLeft="25dp" 
     android:layout_marginTop="20dp" 
     android:layout_marginRight="75dp" 
     android:textStyle="bold" 
     android:padding="10dp"/> 
<TableLayout 
     android:id="@+id/tableLayout1"  
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"  
     android:gravity="top"  
     android:stretchColumns="1">  
    <TableRow 
     android:id="@+id/row2" 
     android:layout_marginTop="45dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
    <EditText 
     android:inputType="text" 
     android:id="@+id/editUsername" 
     android:layout_width="fill_parent" 
     android:layout_height="40dp" 
     android:layout_weight="2" 
     android:singleLine="true" 
     android:hint="input field1" 
     android:layout_marginLeft="25dp" 
     android:layout_marginTop="2dip" 
     android:layout_marginRight="75dp" 
     android:padding="10dp"/> 
</TableRow> 
<TableRow 
    android:id="@+id/row2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <EditText 
     android:inputType="text" 
     android:id="@+id/editUsername" 
     android:layout_width="fill_parent" 
     android:layout_height="40dp" 
     android:layout_weight="2" 
     android:singleLine="true" 
     android:hint="input field2" 
     android:layout_marginLeft="25dp" 
     android:layout_marginTop="2dip" 
     android:layout_marginRight="75dp" 
     android:padding="10dp"/> 
</TableRow>    
    <TableRow 
    android:id="@+id/row2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <EditText 
     android:inputType="text" 
     android:id="@+id/editUsername" 
     android:layout_width="fill_parent" 
     android:layout_height="40dp" 
     android:layout_weight="2" 
     android:singleLine="true" 
     android:hint="input field3" 
     android:layout_marginLeft="25dp" 
     android:layout_marginTop="2dip" 
     android:layout_marginRight="75dp" 
     android:padding="10dp"/> 
</TableRow>  
    <TableRow 
    android:id="@+id/row2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <EditText 
     android:inputType="text" 
     android:id="@+id/editUsername" 
     android:layout_width="fill_parent" 
     android:layout_height="40dp" 
     android:layout_weight="2" 
     android:singleLine="true" 
     android:hint="input field4" 
     android:layout_marginLeft="25dp" 
     android:layout_marginTop="2dip" 
     android:layout_marginRight="75dp" 
     android:padding="10dp"/> 
</TableRow> 
    <RelativeLayout 
     android:id="@+id/linearlayout" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:gravity="bottom" > 
     <Button 
     android:id="@+id/takephoto" 
     android:layout_width="110dp" 
     android:layout_height="35dp" 
     android:text="takephoto"     
     android:textStyle="bold" 
     android:layout_marginLeft="102dp" /> 
    </RelativeLayout> 

+0

Спасибо @NagarjunaReddy, но у этого есть только текст, на каждой вкладке я посмотрел на этот, но ни один из этих примеров не объясняет, как использовать макеты под каждой вкладкой, например, вместо текста I хотите иметь макет таблицы. –

+0

Добавить макет к классам, которые вы создали для каждой вкладки. Табы будут видны в каждом действии. – AndroidLearner

+0

@ пользователь1163454 да можно попробовать ... – NagarjunaReddy

Смежные вопросы