Android 如何在布局xml中保证某个元素以其全高显示
我是Android新手,注意到当创建一个包含Android 如何在布局xml中保证某个元素以其全高显示,android,android-layout,android-resources,Android,Android Layout,Android Resources,我是Android新手,注意到当创建一个包含FrameLayout和TabWidget的带有LinearLayout的TabHost时,声明顺序非常重要。例如,如果我使用: <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp">
FrameLayout
和TabWidget
的带有LinearLayout
的TabHost
时,声明顺序非常重要。例如,如果我使用:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
。。。两者都显示,但选项卡widget
位于顶部,而不是底部,这正是我想要的
因此,我想知道是否有一个
布局高度规范或其他属性可以“保证”在考虑其他元素之前,将某个元素渲染到其完整高度。在您的第一个示例中,您告诉框架布局根据其拥有的内容的多少选择所需的高度:
android:layout_height = "wrap_content"
我猜他没有留下空间来放这个小部件
你的问题的答案是:
android:layout_(dimension) = "fill_parent"
这一个占满了空间。我应该提到,我尝试了fill\u parent
,但问题是顺序很重要,所以既然我希望FrameLayout
位于TabWidget
之上,无论我指定的是wrap\u content
还是fill\u parent
都会填充整个屏幕,不会给糟糕的选项卡栏留下任何空间。如果您想绘制这两个小部件,我建议您使用安卓:weight属性,这肯定会帮助您根据需要缩放小部件,或者有另一种解决方案指定小部件的确切高度和宽度(以像素为单位),但我不建议您使用它,因为它不会在不同的屏幕大小之间缩放。第一种解决方案更好。祝您好运
android:layout_(dimension) = "fill_parent"