繁体   English   中英

Android App中XML表中的垂直和水平方向组合

[英]Combined Vertical and horizontal orientation in XML table in Android App

我需要定义具有垂直和水平方向组合的表格。

我尝试了各种XML定义,但到目前为止都没有成功。

我当前的代码如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.appname.td.MainActivity">
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/tlGridTable" >
        <TableRow>
            <View
                android:layout_width="2dp"
                android:layout_height="18dp"
                android:background="#FF9090" />
            <ImageView
                android:id="@+id/icon"
                android:layout_width="18dp"
                android:layout_height="18dp"
                android:src="@drawable/left_logo_dummy" />
            <View
                android:layout_width="2dp"
                android:layout_height="18dp"
                android:background="#FF9090" />
            <TextView
                android:layout_column="1"
                android:textSize="13sp"
                android:text="Name" />
            <View
                android:layout_width="2dp"
                android:layout_height="18dp"
                android:background="#FF9090" />
            <TextView
                android:rotation="270"
                android:textSize="13sp"
                android:layout_height="match_parent"
                android:layout_width="18dp"
                android:text="29-May"
                android:background="#00ff22"/>
            <View
                android:rotation="0"
                android:layout_width="2dp"
                android:layout_height="18dp"
                android:background="#FF9090" />
            <TextView
                android:textSize="13sp"
                android:text="30-May"
                android:layout_width="18dp"
                android:background="#00ff22" />
        </TableRow>
        <View
            android:layout_height="2dip"
            android:background="#FF9090" />

        <TableRow>
            <View
                android:layout_width="2dp"
                android:layout_height="18dp"
                android:background="#FF9090" />
            <TextView
                android:textSize="13sp"
                android:layout_width="18dp"
                android:layout_height="18dp"
                android:text="1"
                android:background="#00ff22"/>
            <View
                android:layout_width="2dp"
                android:layout_height="18dp"
                android:background="#ff9090" />
            <TextView
                android:layout_column="1"
                android:layout_width="match_parent"
                android:textSize="13sp"
                android:text="Uttam" />
            <View
                android:layout_width="2dp"
                android:layout_height="18dp"
                android:background="#FF9090" />
            <TextView
                android:textSize="13sp"
                android:layout_width="18dp"
                android:text="Y"
                android:background="#00ff22" />
            <View
                android:layout_width="2dp"
                android:layout_height="18dp"
                android:background="#FF9090" />
            <TextView
                android:textSize="13sp"
                android:layout_width="18dp"
                android:text="N"
                android:background="#00ff22" />
        </TableRow>
        <View
            android:layout_height="2dip"
            android:background="#FF9090" />
</TableLayout>
</android.support.constraint.ConstraintLayout>

我仅在实验包含“ 5月29日”的单元格。 由于第二行及以后的每个单元格仅包含一个字母“ Y”或“ N”,我希望日期与底部“ 5月29日”中的“ 2”垂直对齐。

无论我尝试什么,都无法获得该列的水平宽度18dp和垂直高度108dp。 如果将“ layout_height”更改为108dp,则整个单元格将变为108dp x 108dp的正方形。

我做错了,这是微不足道的,但我不能让世界知道它是什么。

这里有人可以帮忙吗?

您应该将ListView与具有以下layout Custom adapter一起使用

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >



            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:background="@color/BGo"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="120dp"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Date"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="120dp"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Day"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView3"
                    android:layout_width="120dp"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Activity Type"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView4"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Location Planned"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Remark"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView6"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Status"
                    android:textColor="@color/White" />
            </LinearLayout>

            <ListView
                android:id="@android:id/list"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:divider="@color/BGo"
                android:dividerHeight="1dp" >
            </ListView>
        </LinearLayout>
    </HorizontalScrollView>

</LinearLayout>

暂无
暂无

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

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