【问题标题】:TableRow TextView moves down on longer TextTableRow TextView 在较长的文本上向下移动
【发布时间】:2018-02-04 19:30:08
【问题描述】:

我尝试通过使用带有 TableRow 的 TableLayout 和 TextView 来为我的学校制作一个时间表应用程序。问题是当我输入更长的文本时,TextView 会向下移动。 这是我的xml: `

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <TextView
            android:layout_width="0dp"
            android:layout_height="60dp"
            android:text="Mo"
            android:background="#ffffff"
            android:gravity="center"
            android:layout_margin="1dp"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="60dp"
            android:gravity="center"
            android:text="Tu"
            android:background="#ffffff"
            android:layout_margin="1dp"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="60dp"
            android:text="WeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWe"
            android:gravity="center"
            android:background="#ffffff"
            android:layout_margin="1dp"
            />

    </TableRow>
</TableLayout>`

and here is a picture of what it looks like

【问题讨论】:

    标签: android android-layout textview tablelayout tablerow


    【解决方案1】:

    更新您的布局类型。 这似乎工作正常。根据需要更改 textColor 和其他参数

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TableRow
            android:id="@+id/tableRow"
            android:layout_width="wrap_content"
            android:layout_height="60dp">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="60dp"
                android:layout_margin="1dp"
                android:background="#ffffff"
                android:text="Mo"
                android:textColor="@color/colorPrimaryDark" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="60dp"
                android:layout_margin="1dp"
                android:background="#ffffff"
                android:text="Tu"
                android:textColor="@color/colorPrimaryDark" />
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_margin="1dp"
                android:background="#ffffff"
                android:gravity="center"
                android:text="WeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWe"
                android:textColor="@color/colorPrimaryDark" />
    
        </TableRow>
    
    </TableLayout>
    
    </RelativeLayout>
    

    【讨论】:

    • 我使用了一个相对布局,里面有一个表格布局,在表格布局中有表格行,里面有文本视图
    • 问题是我想要表格行的固定高度
    • 它仍然做同样的事情,但现在你看不到它,因为文本视图背景与其余部分相同。但我需要表格的背景与网格不同
    • 好的,它将文本基线与其他文本视图的基线对齐。我可以把它关掉吗?一旦我将第一个或第二个 textView 重力设置为居中,它就会再次向下移动
    • 我更新了,再试一次
    猜你喜欢
    • 2018-07-13
    • 1970-01-01
    • 2017-03-02
    • 1970-01-01
    • 2011-10-05
    • 2011-07-10
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多