0

我使用 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>
4

1 回答 1

0

我认为你需要替换GridLayoutTableRow

此布局例如作为您的要求

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:orientation="vertical" >

          <TableRow
              android:paddingTop="10dip"
              android:paddingLeft="10dip"
              android:paddingRight="10dip"
              android:paddingBottom="3dip"
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
          <Button
            android:id="@+id/button1"
            android:layout_weight=".2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 1" />
          <Button
            android:id="@+id/button2"
            android:layout_weight=".2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 2" />
         </TableRow>
          <TableRow
              android:paddingTop="10dip"
              android:paddingLeft="10dip"
              android:paddingRight="10dip"
              android:paddingBottom="3dip"
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
          <Button
            android:id="@+id/button3"
            android:layout_weight=".2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 3" />
          <Button
            android:id="@+id/button4"
            android:layout_weight=".2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 4" />
        </TableRow>

</LinearLayout>
</FrameLayout>

结果

在此处输入图像描述

于 2013-11-03T14:15:59.000 回答