2012-04-27 3 views
3

이클립스의 XML 편집기에서 탭 호스트를보고 정확히 원하는 모양으로 보이지만 실행하면 tabHost가 전혀 표시되지 않습니다. 어떻게 보이게 할 수 있습니까?Android 탭 호스트가 표시되지 않습니까? 왜이 XML에 표시되지 않습니까?

이것은 내 XML입니다. 다시 편집자가 보여 주지만 편집자가 그것을 실행할 때, 그것을 부 풀리는 활동은 아직 많이하지 않습니다. 두 텍스트 필드를 변경하십시오. 어떤 아이디어?

<?xml version="1.0" encoding="utf-8"?> 
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:columnCount="2" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="238dp" 
     android:layout_column="0" 
     android:layout_columnSpan="2" 
     android:layout_gravity="top|left" 
     android:layout_marginTop="7dp" 
     android:layout_marginLeft="3dp" 
     android:layout_row="0" 
     android:gravity="top" 
     android:maxLines="1" 
     android:padding="3dp" 
     android:text="Motherfucking Acer Laptop X314134" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <View 
     android:layout_height="2dp" 
     android:layout_width="fill_parent" 
     android:layout_row="1" 
     android:layout_column="0" 
     android:layout_columnSpan="2" 
     android:background="#FF000000" 
     /> 

    <TabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_column="0" 
     android:layout_columnSpan="2" 
     android:layout_gravity="center_horizontal" 
     android:layout_row="2" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" > 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 
      </TabWidget> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 

       <LinearLayout 
        android:id="@+id/Info" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/Specs" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/Fotos" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/Prijzen" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </LinearLayout> 
      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 

    <TextView 
     android:id="@+id/score" 
     android:layout_column="1" 
     android:layout_marginRight="3dp" 
     android:layout_marginTop="4dp" 
     android:layout_gravity="right" 
     android:layout_row="0" 
     android:gravity="center_vertical" 
     android:padding="3dp" 
     android:text="100%" 
     android:textSize="24sp" /> 

    <Space 
     android:id="@+id/space2" 
     android:layout_width="1dp" 
     android:layout_height="40dp" 
     android:layout_column="0" 
     android:layout_gravity="left" 
     android:layout_row="0" /> 

    <Space 
     android:id="@+id/space1" 
     android:layout_width="1dp" 
     android:layout_height="415dp" 
     android:layout_column="0" 
     android:layout_gravity="left" 
     android:layout_row="2" /> 

</GridLayout> 
+0

레이아웃을 어떻게 팽창 시키나요? –

+0

public void onCreate (Bundle savedInstanceState) { \t \t super.onCreate (savedInstanceState); setContentView (R.layout.product); – Gido

답변

7

당신은 예를 들어, 프로그램이 작업을 수행해야한다 : 좀 더 자세하게 들어

tabhost = (TabHost) findViewById(android.R.id.tabhost); 
    tabhost.setup(); 
    TabSpec ts = tabhost.newTabSpec("tag1"); 
    ts.setContent(R.id.tab1); 
    ts.setIndicator("First Tab"); 
    tabhost.addTab(ts); 

    ts = tabhost.newTabSpec("tag2"); 
    ts.setContent(R.id.tab2); 
    ts.setIndicator("Second Tab"); 
    tabhost.addTab(ts); 
    ts= tabhost.newTabSpec("tag3"); 
    ts.setContent(R.id.tab3); 
    ts.setIndicator("Third Tab"); 
    tabhost.addTab(ts); 
+0

니스 !! 그러나 'tag1','tag2' 및'tag3'의 의미는 무엇입니까? –

+0

@AdilMalik 안녕하세요! Android Dev 문서는 다소 모호하지만 탭을 추적하는 데 사용되는 태그 여야합니다. – Ant4res

-2

을,이 페이지 :

http://mobileorchard.com/android-app-development-tabbed-activities/

은 저작권법과 수있는 좋은 예를 가지고 붙여 넣기에서 XML로 탭을 설정하고 Java로 확장합니다. 모두 하나의 Java 활동으로 이루어집니다. (모든 휴대 전화에서 xml 파일의 "px"단위를 "dp"로 변경하면 모양이 잘 보이게됩니다.)

관련 문제