将 Tablayout 对齐到 AppbarLayout 的底部
Align Tablayout to bottom of AppbarLayout
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"/>
</android.support.design.widget.AppBarLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white"/>
</LinearLayout>
然而,以下是屏幕上显示的布局。我无法让选项卡与 AppbarLayout 的底部对齐。有没有办法让他们对齐到底部?
如果您查看 Android 文档,AppBarLayout 是 LinearLayout 的子项。所以你应该能够像在 LinearLayout 中一样强制子视图到底部 - 使用权重。您可以简单地添加一个 Space 小部件来获取 Toolbar 和 TabLayout 之间剩余的 space 并赋予它们所需的权重(您可能需要进行一些试验和错误才能获得精确的权重值)。
您只需将 TabLayout
放在高度 match_parent
的 LinearLayout
中,并将 gravity
设置为 bottom
。像这样
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"/>
</LinearLayout
希望这会奏效。
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"/>
</android.support.design.widget.AppBarLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white"/>
</LinearLayout>
然而,以下是屏幕上显示的布局。我无法让选项卡与 AppbarLayout 的底部对齐。有没有办法让他们对齐到底部?
如果您查看 Android 文档,AppBarLayout 是 LinearLayout 的子项。所以你应该能够像在 LinearLayout 中一样强制子视图到底部 - 使用权重。您可以简单地添加一个 Space 小部件来获取 Toolbar 和 TabLayout 之间剩余的 space 并赋予它们所需的权重(您可能需要进行一些试验和错误才能获得精确的权重值)。
您只需将 TabLayout
放在高度 match_parent
的 LinearLayout
中,并将 gravity
设置为 bottom
。像这样
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"/>
</LinearLayout
希望这会奏效。