我使用 GridLayout 创建了一个活动,以在屏幕上显示 4 个按钮 - 它们水平和垂直显示在屏幕中央。
我现在已使用http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/上的指南将活动更改为在选项卡内显示的片段
但是选项卡显示全部与屏幕的左上角对齐。
**我想要一个在屏幕中间水平和垂直方向都有 4 个按钮的显示器 *
BTN 1 BTN 2
BTN 3 BTN 4
这是我的片段布局文件
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:columnCount="2"
android:orientation="horizontal" >
<Button
android:id="@+id/Btn_Show"
android:text="Btn Show"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_column="0"
android:drawableTop="@drawable/ic_launcher" />
<Button
android:id="@+id/Btn_2"
android:text="Btn 2"
android:layout_width="100dp"
android:layout_height="100dp"
android:drawableTop="@drawable/ic_launcher" />
<Button
android:id="@+id/Btn_3"
android:text="Btn 3"
android:layout_width="100dp"
android:layout_height="100dp"
android:drawableTop ="@drawable/ic_launcher" />
<Button
android:id="@+id/Btn_4"
android:text="Btn 4"
android:layout_width="100dp"
android:layout_height="100dp"
android:drawableTop="@drawable/ic_launcher" />
</GridLayout>
这是包含片段作为选项卡的活动的主要布局
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>