代码之家  ›  专栏  ›  技术社区  ›  Absar Ahmad

有没有办法通过XML在android中实现这种表格布局?

  •  0
  • Absar Ahmad  · 技术社区  · 5 年前

    我试图制作一个表,有4列7行,但第一列有0行。这个表有XML解决方案吗?我正在附上我需要制作的桌子图片。

    This is the table I am trying to make

    0 回复  |  直到 5 年前
        1
  •  0
  •   Lee ABK    5 年前

    你可以试着做:

    1. 3列7行表格

    2. 在桌子的左边有一个文本视图

      <文本框 android:id=“@+id/textView”

      android:layout_width=“match_parent”

      android:layout_height=“wrap_content”

      安卓:text=“午餐” android:rotation=“-90” />

        2
  •  0
  •   Absar Ahmad    5 年前

    下面的代码对我很有用,完全符合我的要求。

        <?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>