将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.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>

However the following is the layout which is presented on the screen. I can't get the tabs to align to the bottom of the AppbarLayout. Is there a way for them to align to bottom?

最满意答案

您可以简单地将TabLayout封装在一个LinearLayout ,其高度为match_parent并将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

希望这会奏效。

You can simply enclose your TabLayout inside a LinearLayout with height match_parent and setting gravity to bottom. Something like this

<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

Hope this will work.

更多推荐