繁体   English   中英

我应该使用哪种布局来在 android 中制作表格类型的布局?

[英]which layout should i use for making a table type layout in android?

我想做这样的布局:

在此处输入图片说明

谁能指导我哪种布局更合适?(我有固定的行数和列数)。

相对布局还是线性布局? 或者是其他东西?

使用以下代码进行您想要的设计

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
 android:layout_width="match_parent"
android:layout_height="match_parent">
 <LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <RelativeLayout
        android:background="#8FDFBF"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_marginEnd="1dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/card_title1"
            android:text="title1"
            android:textColor="@android:color/white"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_below="@+id/card_title1"
            android:layout_marginTop="20dp"
            android:text="12"
            android:textColor="@android:color/white"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_weight="1"
        android:background="#8FDFBF"
        android:gravity="center"
        android:layout_marginStart="1dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/card_title2"
            android:text="title2"
            android:textColor="@android:color/white"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_below="@+id/card_title2"
            android:layout_marginTop="20dp"
            android:text="21"
            android:textColor="@android:color/white"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </RelativeLayout>

</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_marginTop="@dimen/margin_2"
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <RelativeLayout
        android:background="#4ADCA1"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_marginEnd="1dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/card_title3"
            android:text="title3"
            android:gravity="center"
            android:textColor="@android:color/white"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_below="@+id/card_title3"
            android:layout_marginTop="20dp"
            android:text="25 c"
            android:textColor="@android:color/white"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_weight="1"
        android:background="#4ADCA1"
        android:gravity="center"
        android:layout_marginStart="1dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/card_title4"
            android:text="title4"
            android:gravity="center"
            android:textColor="@android:color/white"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_below="@+id/card_title4"
            android:layout_marginTop="20dp"
            android:text="40 mb"
            android:textColor="@android:color/white"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </RelativeLayout>

</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_marginTop="@dimen/margin_2"
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <RelativeLayout
        android:background="#9EFAD5"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_marginEnd="1dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/card_title5"
            android:text="title5"
            android:textColor="@android:color/white"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_below="@+id/card_title5"
            android:layout_marginTop="20dp"
            android:text="50 %"
            android:textColor="@android:color/white"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_weight="1"
        android:background="#9EFAD5"
        android:gravity="center"
        android:layout_marginStart="1dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/card_title6"
            android:text="title6"
            android:gravity="center"
            android:textColor="@android:color/white"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_below="@+id/card_title6"
            android:layout_marginTop="20dp"
            android:text="90 %"
            android:textColor="@android:color/white"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </RelativeLayout>

</LinearLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM