Android 安卓:布局_marginBottom底部不留空间
我的项目中有一个TabHost活动。当我有下面的XML时,选项卡就不在屏幕上了,它们根本不显示Android 安卓:布局_marginBottom底部不留空间,android,android-linearlayout,android-tabhost,android-framelayout,tabwidget,Android,Android Linearlayout,Android Tabhost,Android Framelayout,Tabwidget,我的项目中有一个TabHost活动。当我有下面的XML时,选项卡就不在屏幕上了,它们根本不显示 <TabHost xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/tabHost" android:layout_width="match_parent" androi
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activityVerticalMargin"
android:paddingLeft="@dimen/activityHorizontalMargin"
android:paddingRight="@dimen/activityHorizontalMargin"
android:paddingTop="@dimen/activityVerticalMargin"
tools:context=".SomeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp">
<some elements here>
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="50dp" />
</LinearLayout>
</TabHost>
但是,如果我稍微修改一下,使其看起来像这样,选项卡会显示出来,但它们不在底部,也不是我想要的样子
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activityVerticalMargin"
android:paddingLeft="@dimen/activityHorizontalMargin"
android:paddingRight="@dimen/activityHorizontalMargin"
android:paddingTop="@dimen/activityVerticalMargin"
tools:context=".SomeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp">
<!-- layout_height above was changed to wrap_content -->
<some elements here>
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="50dp" />
</LinearLayout>
</TabHost>
为什么它在第一种情况下不起作用?版面边距底图不应该使版面的高度
匹配\u parent-margin
(在这种情况下为50dp)?好吧,有一种方法可以通过线性布局来实现这一点(无论如何,我们应该避免相对边距)。我们可以为您的TabWidget
元素提供负边距。以下是您的布局的外观:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activityVerticalMargin"
android:paddingLeft="@dimen/activityHorizontalMargin"
android:paddingRight="@dimen/activityHorizontalMargin"
android:paddingTop="@dimen/activityVerticalMargin"
tools:context=".SomeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp">
<!-- some elements here -->
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="-50dp"/>
</LinearLayout>
</TabHost>
将父线性布局转换为相对线性布局。框架布局应具有参数align\u parenttop=true,并且tabwidget应具有align\u parentBottom=true。剩下的就留着吧 您的代码将与父项匹配-100dp(50dp的tabweight和50dp的marginBottom)。Match_parent将占用线性布局中剩余的所有空间。在relativelayout中,它将是match_parent-50dp(marginbottom的50dp),因此,我应该如何更改它?将parent LinearLayout转换为relativelayout。框架布局应具有参数align\u parenttop=true,并且tabwidget应具有align\u parentBottom=true。剩下的就留着吧。是的,这很有效。奇怪的是,没有办法使用线性布局来实现这一点?它只是在玩不同类型的布局和边距/填充。还有其他方法。除非您需要使用linearlayout的特定功能,否则这应该可以。我已经提交了答案。如果你能把它标记为正确的,那就太好了