Android 在TableRow中使用线性布局

Android 在TableRow中使用线性布局,android,android-linearlayout,tablelayout,Android,Android Linearlayout,Tablelayout,我尝试在我的Android应用程序中使用如下单元格制作表格: (很抱歉出现此链接,由于声誉低下,我无法附加图像) 我的想法是在表格行中使用线性布局,但工作不正确。 请,如果你有任何关于如何修改表布局的想法,以工作如我所期望的-给我任何想法 我的xml代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/t

我尝试在我的Android应用程序中使用如下单元格制作表格:

(很抱歉出现此链接,由于声誉低下,我无法附加图像)

我的想法是在表格行中使用线性布局,但工作不正确。 请,如果你有任何关于如何修改表布局的想法,以工作如我所期望的-给我任何想法

我的xml代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="@color/black"
    android:orientation="vertical" >

    <TableLayout
        style="@style/TextColor"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="90"
        android:stretchColumns="1"
        android:textColor="@colors/white" >

        <TableRow>

        <TextView
            style="@style/TextColor"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@drawable/cell"
            android:gravity="center"
            android:padding="10dip"
            android:singleLine="false"
            android:text="@string/start_time" />

            <TextView
                style="@style/TextColor"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/cell"
                android:gravity="center"
                android:padding="10dip"
                android:text="@string/start_time" />

        </TableRow>
        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                style="@style/TextColor"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/cell"
                android:gravity="center"
                android:padding="10dip"
                android:text="@string/start_time" />

            <TextView
                style="@style/TextColor"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/cell"
                android:gravity="center"
                android:padding="10dip"
                android:text="@string/start_time" />

        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
             <TextView
                style="@style/TextColor"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/cell"
                android:gravity="center"
                android:padding="10dip"
                android:text="@string/start_time" />
             <TextView
                style="@style/TextColor"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/cell"
                android:gravity="center"
                android:padding="10dip"
                android:text="@string/start_time" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </TableRow>

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </TableRow>

    </TableLayout>

     <TextView
         android:layout_width="fill_parent"
         android:layout_height="0dp"
         android:layout_weight="10"
         android:gravity="center"
         android:text="ADDS" />

</LinearLayout>

编辑 我根据你的意见做了一些修改。请看一看,告诉我为什么不显示文本

    <LinearLayout xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="@color/black"
    android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">

        <LinearLayout 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/black"
            android:orientation="horizontal"
            android:baselineAligned="false" >

            <LinearLayout
                android:layout_weight=".5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/cell"
                android:orientation="vertical" >

                    <TextView
                        android:layout_height="fill_parent"
                        style="@style/TextColor"
                        android:gravity="center"
                        android:padding="10dip"
                        android:text="@string/start_time" />
                    <TextView
                        style="@style/TextColor"
                        android:gravity="center"
                        android:padding="10dip"
                        android:text="@string/activate" />
            </LinearLayout>

            <LinearLayout 
                android:layout_weight=".5"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:background="@drawable/cell"
                android:orientation="vertical" >
                    <TextView
                        android:layout_height="fill_parent"
                        style="@style/TextColor"
                        android:gravity="center"
                        android:padding="10dip"
                        android:text="@string/start_time" />
                    <TextView
                        style="@style/TextColor"
                        android:gravity="center"
                        android:padding="10dip"
                        android:text="@string/activate" />
            </LinearLayout>
        </LinearLayout>

试试这个

<TableRow
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_gravity="center_horizontal"
    android:orientation="vertical"
    android:id="@+id/row">


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/container">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Large Text"
            android:paddingLeft="20dp"
            android:id="@+id/textView" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="Small Text"
            android:id="@+id/textView2"
            android:layout_centerVertical="true"
            android:layout_alignRight="@+id/textView"
            android:paddingTop="20dp"
            android:paddingLeft="20dp"
            android:layout_alignEnd="@+id/textView" />
        </LinearLayout>
</TableRow>

对于border,将其放在名为border.xml的文件中

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
    <solid android:color="#00000000"/>
    <stroke android:width="1dp"  android:color="#000000"/>
</shape>

要绘制内部内容,请使用此

<LinearLayout 
android:layout_margin="5dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/border">
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="24sp"
    android:text="Sample Text"/>
<TextView 
    android:layout_marginTop="10dp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="11sp"
    android:text="Sample Text"/>

您可以在
表格行中使用
LinearLayout
,也可以在任何需要的地方使用
谢谢您的帮助。
我找到了一个解决办法。
我的xml文件现在看起来像这样:



为什么只使用垂直线性布局?发布完整的布局。我是android开发的新手,所以请尽管这个问题看起来很愚蠢,给我一个建议。如果你需要一个带有边框的框,并且框内有两行垂直的文本,只需使用
LinearLayout
,将
background
属性设置为可以绘制边框的可绘制属性。然后在
LinearLayout
框内有
orientation=vertical
使用两个
TextView
不同的字体大小。黛布,我需要一个5x2的格子。我现在会尝试使用线性布局,谢谢你,但是没有帮助。这一行根本不显示。你能告诉我你面临什么问题吗?问题视图根本不可见吗?文本未显示。请检查编辑的帖子。我添加了线性布局的代码。在
TextView
中,您可以删除
style
属性并使用
android:textColor=“@color/white”
。您的颜色中需要白色。xml
#FFFFFF
<LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/black"
        android:orientation="horizontal"
        android:baselineAligned="false" >

        <LinearLayout
            android:layout_weight=".5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/cell"
            android:orientation="vertical" >

                <TextView
                    style="@style/TextColor"
                    android:layout_width="fill_parent" 
                    android:layout_height="fill_parent" 
                    android:gravity="center"
                    android:padding="10dip"
                    android:textSize="46sp"
                    android:text="@string/start_time" />

                <TextView
                    style="@style/TextColor"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:padding="10dip"
                    android:paddingBottom="@dimen/zero"
                    android:text="@string/activate" />

        </LinearLayout>

        <LinearLayout 
            android:layout_weight=".5"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:background="@drawable/cell"
            android:orientation="vertical" >
                <TextView
                    android:layout_width="fill_parent" 
                    android:layout_height="fill_parent"
                    style="@style/TextColor"
                    android:gravity="center"
                    android:padding="10dip"
                    android:textSize="46sp"
                    android:text="@string/start_time" />
                <TextView
                    android:layout_width="fill_parent" 
                    android:layout_height="fill_parent"
                    style="@style/TextColor"
                    android:gravity="center"
                    android:padding="10dip"
                    android:text="@string/activate" />
        </LinearLayout>