Android Material Design TabLayout属性app:tabMode和app: tabGravity
生活随笔
收集整理的這篇文章主要介紹了
Android Material Design TabLayout属性app:tabMode和app: tabGravity
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Android Material Design TabLayout屬性app:tabMode和app: tabGravity
Android Material Design 中的TabLayout有兩個比較有用的屬性 app:tabMode、app:tabGravity,
(1)app:tabMode有兩個值:fixed和scrollable。
(2)app:tabGravity有兩個值:fill和center。
比較常用的是app:tabMode設置值scrollable,以及app:tabGravity設置值center。
比如,當app:tabMode設置值scrollable表示此TabLayout中當子view超出屏幕邊界時候,將提供滑動以便滑出不可見的那些子view。
而app:tabGravity設置值center,在有些情況下,比如TabLayout中子view較少需要居中顯示時候的情景。
現在給出一個例子加以說明。
測試的MainActivity.java:
MainActivity.java需要的布局文件activity_main.xml文件:
<?xml version="1.0" encoding="utf-8"?> <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="wrap_content"android:orientation="vertical" ><android.support.design.widget.TabLayoutandroid:id="@+id/tabLayout1"android:layout_width="match_parent"android:layout_height="wrap_content"app:tabGravity="fill"app:tabMode="fixed" /><android.support.design.widget.TabLayoutandroid:id="@+id/tabLayout2"android:layout_width="match_parent"android:layout_height="wrap_content"app:tabGravity="center"app:tabMode="fixed" /><android.support.design.widget.TabLayoutandroid:id="@+id/tabLayout3"android:layout_width="match_parent"android:layout_height="wrap_content"app:tabGravity="fill"app:tabMode="scrollable" /><android.support.design.widget.TabLayoutandroid:id="@+id/tabLayout4"android:layout_width="match_parent"android:layout_height="wrap_content"app:tabGravity="center"app:tabMode="scrollable" /></LinearLayout>效果如圖所示:
總結
以上是生活随笔為你收集整理的Android Material Design TabLayout属性app:tabMode和app: tabGravity的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 你是个有魅力的人吗?人格魅力这样修养而成
- 下一篇: 【转】Thunderbird中配置签名