【问题标题】:Linear layout inside TabHost only showing one elementTabHost 内的线性布局仅显示一个元素
【发布时间】:2011-04-26 15:59:04
【问题描述】:

我的 android 应用程序中有这个布局文件:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1">
            <TextView 
                android:id="@+id/textview1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is a tab" />
            <TextView 
                android:id="@+id/textview2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is another tab" />
            <LinearLayout
                android:id="@+id/layoutSearch"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical">
                <TextView
                    android:id="@+id/textview4"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" 
                    android:text="Search here" />
                <EditText
                    android:id="@+id/editSearch"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>
        </FrameLayout>
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/>
    </LinearLayout>
</TabHost>

我的问题是LinearLayout android:id="@+id/layoutSearch" 只显示它包含的元素之一(文本视图,在上面的代码中)如果我删除文本视图,它会显示 EditText。

如何让它显示两个(以及更多)元素?

【问题讨论】:

  • 我知道这看起来像是我在复制 iPhone 应用程序,但 IMO 这使得看到屏幕的其余部分更容易,当它们在顶部时,你的手会覆盖整个屏幕。
  • 你说得对,也许我应该把它移上去,我会考虑的

标签: android tabview android-linearlayout


【解决方案1】:

那里有很多多余的布局,但看起来真正的问题是layoutSearch 是一个带有两个孩子的垂直LinearLayout,但是第一个孩子的高度设置为fill_parent,所以你自然不会看到第二个一。尝试将其高度设置为0px,但将其设置为layout_weight1,它应该扩展以占用其下方EditText 未占用的所有可用空间。

【讨论】:

  • 我将高度更改为wrap_content,现在可以使用了。还有一个问题:你说有很多多余的布局..你如何建议我以更好的方式做到这一点?感谢您的帮助!
  • 哦,我只是说相对于您的问题,layoutSearch 周围的所有容器内容都不相关。不过,如果您愿意的话,您可能可以使用 RelativeLayout 将事情弄平。
  • 啊,对了,我不知道是哪个部分导致了问题,所以我发布了所有内容。无论如何,再次感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-04
  • 1970-01-01
  • 1970-01-01
  • 2012-01-29
  • 1970-01-01
  • 2020-06-29
  • 1970-01-01
相关资源
最近更新 更多