Android 文本视图高度与父对象/填充父对象不匹配
我有一个简单的文本视图,只有一行。 我想将高度设置为匹配\u parent/fill\u parent,但Android的行为是仅包装\u内容 有没有办法强制TextView采用所有高度 Tkx 编辑: 这就是我得到的: 和我的布局:Android 文本视图高度与父对象/填充父对象不匹配,android,android-layout,layout,textview,fill-parent,Android,Android Layout,Layout,Textview,Fill Parent,我有一个简单的文本视图,只有一行。 我想将高度设置为匹配\u parent/fill\u parent,但Android的行为是仅包装\u内容 有没有办法强制TextView采用所有高度 Tkx 编辑: 这就是我得到的: 和我的布局: <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView
<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>
[...]
对于TextView
父宽度,您可以使用wrap\u content
您可以将文本视图高度设置为匹配父项/填充父项。并根据需要更改文本视图的重力和所有其他属性
如果这对你来说还不够,那么让我知道你到底想做什么
编辑:
根据你新编辑的代码,我对你的代码进行了修改
<?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>
现在它在整个屏幕的中央垂直位置显示文本视图
试试这个代码。它起作用了。更改您的RelativeLayout和文本视图。也有同样的问题,您是否最终解决了其他问题或此方案?