Android中的Complexe表/网格布局

时间:2017-05-04 19:04:47

标签: android

我试图做一个看起来像这样的视图 enter image description here

每个UI都是textview或button。我一直工作了5个小时没有得到适当的结果。我尝试了TableLayout和gridLayout。我没有想法。

1 个答案:

答案 0 :(得分:1)

如果您使用的是v7支持库中的GridLayout。

compile 'com.android.support:gridlayout-v7:22.2.1'

参考此代码,

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.GridLayout 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_column="4"
    android:layout_row="5"
    android:layout_height="match_parent">

    <Button android:layout_width="0dp"
        app:layout_column="0"
        app:layout_columnWeight="1"
        app:layout_row="0"
        android:layout_height="wrap_content"/>

    <Button android:layout_width="0dp"
        app:layout_column="1"
        app:layout_columnWeight="1"
        app:layout_row="0"
        android:layout_height="wrap_content"/>

    <Button android:layout_width="0dp"
        app:layout_column="2"
        app:layout_columnWeight="1"
        app:layout_row="0"
        android:layout_height="wrap_content"/>

    <Button android:layout_width="0dp"
        app:layout_column="3"
        app:layout_row="0"
        app:layout_columnWeight="1"
        android:layout_height="wrap_content"/>

    <!-- 2nd -->

    <Button android:layout_width="0dp"
        app:layout_column="0"
        app:layout_columnSpan="4"
        app:layout_row="1"
        app:layout_columnWeight="1"
        android:layout_height="wrap_content"/>

    <!-- 2nd -->
    <Button android:layout_width="0dp"
        app:layout_column="0"
        app:layout_row="2"
        app:layout_columnWeight="1"
        android:layout_height="wrap_content"/>

    <Button android:layout_width="0dp"
        app:layout_column="1"
        app:layout_row="2"
        app:layout_columnWeight="1"
        android:layout_height="wrap_content"/>

    <Button android:layout_width="0dp"
        app:layout_column="2"
        app:layout_row="2"
        app:layout_columnSpan="2"
        app:layout_columnWeight="2"
        android:layout_height="wrap_content"/>
    <!-- 3rd -->
    <Button android:layout_width="0dp"
        app:layout_column="0"
        app:layout_row="3"
        app:layout_columnSpan="2"
        app:layout_columnWeight="1"
        android:layout_height="wrap_content"/>

    <Button android:layout_width="0dp"
        app:layout_column="2"
        app:layout_row="3"
        app:layout_columnSpan="2"
        app:layout_rowSpan="3"
        app:layout_columnWeight="1"
        android:layout_height="wrap_content"/>

    <!-- 3rd -->

    <Button android:layout_width="0dp"
        app:layout_column="0"
        app:layout_row="4"
        app:layout_columnWeight="1"
        android:layout_height="wrap_content"/>

    <Button android:layout_width="0dp"
        app:layout_column="1"
        app:layout_row="4"
        app:layout_columnWeight="1"
        android:layout_height="wrap_content"/>
    <!-- 3rd -->
    <Button android:layout_width="0dp"
        app:layout_column="0"
        app:layout_row="5"
        app:layout_columnSpan="2"
        app:layout_columnWeight="1"
        android:layout_height="wrap_content"/>



</android.support.v7.widget.GridLayout>