gridlayout可以做到吗?

时间:2016-06-24 08:32:25

标签: android android-layout android-gridlayout

GridLayout我很弱,通常我做的是使用LinearLayout来做我的界面,但今天我想试试Gridlayout

我一直在研究Gridlayout一段时间,只是不明白它,不理解背后的逻辑。

enter image description here

我希望创建一个简单的Gridlayout来存储我的对象,如下所示,有人可以告诉我该怎么做吗?

或者可能Gridlayout不能这样做???

2 个答案:

答案 0 :(得分:3)

也许你可以这样做:

<?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageButton
            android:layout_width="170dp"
            android:layout_height="200dp"
            android:id="@+id/imageButton"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true" />

        <ImageView
            android:layout_width="170dp"
            android:layout_height="200dp"
            android:id="@+id/imageView"
            android:layout_below="@+id/imageButton"
            android:layout_alignParentStart="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="TEXTT"
            android:id="@+id/textView"
            android:layout_alignParentTop="true"
            android:layout_alignBottom="@+id/imageView"
            android:layout_alignParentEnd="true"
            android:layout_toEndOf="@+id/imageButton" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/imageView2"
            android:layout_below="@+id/imageView"
            android:layout_alignParentStart="true" />
    </RelativeLayout>

如果这不是您想要的,那么我可以尝试帮助您:)

答案 1 :(得分:0)

我建议你使用RelativeLayout:

<RelativeLayout>
  <ImageButton id="@+id/img1" 
    alignParentTop="true"
    alignparentLeft="true" />
  <ImageButton layout_below="@id/img1"
    alignparentLeft="true" />
  <TextView alignParentRight="true"
    alignParentTop="true" />
  <ImageView alignParentBottom="true" />
</RelativeLayout>

您需要调整宽度和高度以满足您的要求