【发布时间】:2021-06-18 12:30:51
【问题描述】:
【问题讨论】:
标签: xml android-studio android-layout android-tablelayout
【问题讨论】:
标签: xml android-studio android-layout android-tablelayout
你可以尝试制作:
一个 3 列 7 行的表格
以及表格左侧的 textView
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="午餐"
android:rotation="-90"/>
【讨论】:
constraintlayout 作为父级,然后您可以将Textview 约束到顶部和底部表格,否则旋转的Textview 可能与表格不对齐。
以下代码对我有用,并且完全符合我的要求。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rotation="-90"
android:gravity="center"
android:layout_weight="1"
android:text="Lunch">
</TextView>
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="3"
android:weightSum="3">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Diet">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Quantity">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Image">
</TextView>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Diet">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Quantity">
</TextView>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_weight="1">
</ImageView>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Diet">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Quantity">
</TextView>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_weight="1">
</ImageView>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Diet">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Quantity">
</TextView>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_weight="1">
</ImageView>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Diet">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Quantity">
</TextView>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_weight="1">
</ImageView>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Diet">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Quantity">
</TextView>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_weight="1">
</ImageView>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Diet">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Quantity">
</TextView>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_weight="1">
</ImageView>
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
【讨论】: