如何更改网格视图项高度(第一项高度等于项2和项3)

时间:2017-10-10 05:04:14

标签: android

我想要一个与此类似的网格视图

enter image description here

3 个答案:

答案 0 :(得分:0)

创建具有多个视图持有者的自定义适配器,然后根据您的设计对视图进行充气,以下链接可能更有帮助https://guides.codepath.com/android/Heterogenous-Layouts-inside-RecyclerView

答案 1 :(得分:0)

答案 2 :(得分:0)

试试这段代码:

<GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alignmentMode="alignBounds"
        android:columnCount="2"
        android:columnOrderPreserved="false"
        android:useDefaultMargins="true"
        >

        <Button
            android:layout_rowSpan="2"
            android:layout_column="0"
            android:layout_columnWeight="0.5"
            android:layout_gravity="fill"
            android:layout_row="0"
            android:text="Button 1" />

        <Button
            android:layout_gravity="fill"
            android:layout_column="1"
            android:layout_columnWeight="0.5"
            android:layout_row="0"
            android:text="Button 2" />

        <Button
            android:layout_gravity="fill"
            android:layout_column="1"
            android:layout_row="1"
            android:text="Button 3" />


        <Button
            android:layout_gravity="fill"
            android:layout_column="0"
            android:layout_row="2"
            android:text="Button 4" />

        <Button
            android:layout_gravity="fill"
            android:layout_column="0"
            android:layout_row="3"
            android:text="Button 5" />
        <Button
            android:layout_gravity="fill"
            android:layout_column="1"
            android:layout_row="2"
            android:layout_rowSpan="2"
            android:text="Button 6" />

        <Button
            android:layout_gravity="fill"
            android:layout_column="0"
            android:layout_row="4"
            android:layout_rowSpan="2"
            android:text="Button 7" />
        <Button
            android:layout_gravity="fill"
            android:layout_column="1"
            android:layout_row="4"
            android:text="Button 8" />
        <Button
            android:layout_gravity="fill"
            android:layout_column="1"
            android:layout_row="5"
            android:text="Button 9" />

    </GridLayout>

enter image description here