Android电子标签的Widget将不能填满屏幕的宽度 [英] Android Tab Widget won't fill the width of the screen

查看:120
本文介绍了Android电子标签的Widget将不能填满屏幕的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是全新的Andr​​oid开发人员和XML。我正在试图做的是在屏幕的底部创建4个选项卡,并为标签来填充屏幕的宽度。我已经能够在底部创建4个标签,但即使宽度的都设置为FILL_PARENT选项卡小部件不补的宽度。然而,在Eclipse的图形布局,它显示了插件填充所述宽度。任何人都可以帮忙吗? code如下。谢谢你。

 <?XML版本=1.0编码=UTF-8&GT?;
<! - 都柏林巴士应用程序 - >< TabHost
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:ID =@ + ID / tab_host>    < TabWidget
        机器人:ID =@机器人:ID /标签
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =底/>    <的FrameLayout
        机器人:ID =@机器人:ID / tabcontent
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT>        <的LinearLayout
            机器人:ID =@ + ID / TAB1
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =match_parent
            机器人:方向=垂直
            机器人:填充=5像素>            <的TextView
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:文字=这是第一个选项卡
                机器人:TEXTSIZE =25dp
                机器人:layout_gravity =中心
                机器人:文字样式=大胆/>
        < / LinearLayout中>        <的LinearLayout
            机器人:ID =@ + ID / TAB2
            机器人:方向=垂直
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT
            机器人:填充=5像素>            <的TextView
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:文字=这是第二个选项卡
                机器人:layout_gravity =中心
                机器人:文字样式=大胆
                机器人:TEXTSIZE =25dp/>
            < / LinearLayout中>        <的LinearLayout
            机器人:ID =@ + ID / TAB3
            机器人:方向=垂直
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT
            机器人:填充=5像素>            <的TextView
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:文字=这是第三个选项卡
                机器人:layout_gravity =中心
                机器人:文字样式=大胆
                机器人:TEXTSIZE =25dp/>
        < / LinearLayout中>        <的LinearLayout
            机器人:ID =@ + ID / TAB4
            机器人:方向=垂直
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT
            机器人:填充=5像素>            <的TextView
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:文字=这是第四个选项卡
                机器人:layout_gravity =中心
                机器人:文字样式=大胆
                机器人:TEXTSIZE =25dp/>
        < / LinearLayout中>
    < /&的FrameLayout GT;
< / TabHost>


解决方案

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

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

 <?XML版本=1.0编码=UTF-8&GT?;
<! - 都柏林巴士应用程序 - >< TabHost
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:ID =@ + ID / tab_host>
    <的LinearLayout
        机器人:方向=垂直
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT>        < TabWidget
            机器人:ID =@机器人:ID /标签
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_gravity =底/>        <的FrameLayout
            机器人:ID =@机器人:ID / tabcontent
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT
            机器人:填充=5DP/>
    < / LinearLayout中>
< / TabHost>

然后按照的HelloTabWidget教程以填充标签内容。

I'm completely new to Android dev and XML. What I'm trying to do is create 4 tabs at the bottom of the screen, and for the tabs to fill the width of the screen. I have been able to create the 4 tabs at the bottom, but even though the width's are all set to "fill_parent", the tab widget doesn't fill the width. However, in the graphical layout in Eclipse, it shows the widget filling the width. Can anyone help? Code is below. Thanks.

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

解决方案

Your problem is that TabHost is derived from FrameLayout, which, as the description states, is only for holding one element, and you're stuffing it with two: a TabWidget and a FrameLayout.

Try this: (note how I also removed FrameLayout - trying to fill in tabs like that is a bad idea)

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

Then follow the HelloTabWidget tutorial to fill the tabs with content.

这篇关于Android电子标签的Widget将不能填满屏幕的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆