TextView的高度无法匹配match_parent/fill_parent。

3

我有一个简单的TextView,只有一行。我希望将其高度设置为match_parent/fill_parent,但Android的行为是仅包裹内容。

有没有办法强制TextView占据所有高度?

Tkx

编辑:

这就是我得到的:

enter image description here 和我的布局:

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

<TextView
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center"
        android:paddingLeft="13dp"
        android:paddingRight="3dp"
        android:textColor="@android:color/white"
        android:textStyle="bold" />

        [...]

</RelativeLayout>

你遇到了同样的问题吗?你最终得到了其他的解决方案还是用这种情况解决了? - htafoya
2个回答

0

您可以将 TextView 的高度设置为 match_parent/fill_parent。并根据您的要求更改该 TextViewgravity所有其他属性

如果这对您来说不够,请告诉我您想要做什么。

编辑:

根据您的新编辑代码,我已经处理了您的代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent" 
android:layout_width="match_parent">
<TextView android:id="@+id/date" 
    android:layout_width="wrap_content"
    android:layout_height="match_parent" 
    android:gravity="center"
    android:paddingLeft="13dp" 
    android:paddingRight="3dp"
    android:textStyle="bold" 
    android:textColor="#ffffff" 
    android:text="dateText"/>
</RelativeLayout>

现在它正在整个屏幕的central_vertical位置显示TextView

尝试这段代码。它可以工作。像我一样更改您的RelativeLayoutTextView


0

对于那个 TextView 的父容器宽度,你可以使用 wrap_content


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接