我应该使用哪种布局在 android 中制作 table 类型的布局?
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>
我想做这样的布局:
谁能指导我哪种布局更合适?(我有固定的行数和列数)。
相对布局还是线性布局?或者是其他东西?
使用下面的代码进行你想要的设计
<?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>