的Android的Widget选项卡将不填满屏幕

问题描述:

的宽度,我完全新的Android开发人员和XML。我正在试图做的是在屏幕的底部创建4个标签,并为标签来填充屏幕的宽度。我已经能够在底部创建4个标签,但即使宽度的全部设置为“FILL_PARENT”,标签控件不填充宽度。然而,在Eclipse的图形布局,它示出了插件填充所述宽度。谁能帮忙?代码如下。谢谢。的Android的Widget选项卡将不填满屏幕

<?xml version="1.0" encoding="utf-8"?> 
<!-- Dublin Bus App --> 

<TabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/tab_host"> 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom"/> 

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

     <LinearLayout 
      android:id="@+id/tab1" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:padding="5px" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="This is the first tab" 
       android:textSize="25dp" 
       android:layout_gravity="center" 
       android:textStyle="bold"/> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/tab2" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5px" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="This is the second tab" 
       android:layout_gravity="center" 
       android:textStyle="bold" 
       android:textSize="25dp"/> 
      </LinearLayout> 

     <LinearLayout 
      android:id="@+id/tab3" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5px"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="This is the third tab" 
       android:layout_gravity="center" 
       android:textStyle="bold" 
       android:textSize="25dp"/> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/tab4" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5px"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="This is the fourth tab" 
       android:layout_gravity="center" 
       android:textStyle="bold" 
       android:textSize="25dp"/> 
     </LinearLayout>    
    </FrameLayout> 
</TabHost> 
+0

做你有做同样的任何解决方案?我可以知道你使用的是哪个版本的机器人吗?谢谢 – vinaykumar 2013-07-24 08:56:17

您的问题是TabHost从FrameLayout,其中,作为描述的状态,是衍生仅持有一个元素,而你带馅它两个:一个TabWidget和一个FrameLayout。

试试这个:(注意,我怎么也删除的FrameLayout - 试图填补标签一样,是一个坏主意)

<?xml version="1.0" encoding="utf-8"?> 
<!-- Dublin Bus App --> 

<TabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/tab_host"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom"/> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp" /> 
    </LinearLayout> 
</TabHost> 

然后按照the HelloTabWidget tutorial用内容来填充选项卡。

尝试机器人:宽=“match_parent”

+0

嗨,android:layout_width =“match_parent”导致同样的问题 – sineil 2012-02-10 16:14:42