我添加了第二个 TextView
,它应该位于第一个 TextView
下方,但现在第一个 TextView
正在工作,但第二个没有出现。
这是我的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/state1"
android:textSize="16sp" />
<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_below="@id/textView1"
android:ellipsize="marquee"
android:singleLine="true"
android:text="@string/sayer1"
android:textSize="12sp" />
<TextView
android:id="@+id/thirdLine"
android:layout_below="@+id/textView2"
android:text="@string/state2"
android:textSize="16sp" />
<TextView
android:id="@+id/textView2"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="@string/sayer2"
android:textSize="16sp" />
</RelativeLayout>
最佳答案
您需要三件事才能让其他人出现。
第一:
将此属性 android:layout_height="?android:attr/listPreferredItemHeight"
更改为 android:width="match_parent"
第二个:
为您的 TextView
设置宽度/高度。 thirdLine 和 textView2 没有合适的宽度/高度。尝试这样做:
android:layout_width="match_parent"
android:layout_height="wrap_content"
最后:
不要尝试将 TextView
放置在另一个其对齐方式为 alignParentBottom
的下方。相反,尝试添加一个容器,其对齐方式位于全局父级的底部。见下文:
尝试这种格式:
<?xml version="1.0" encoding="utf-8"?>
// set a height to wrap_content/match_parent/fill_parent
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="6dip" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="state1"
android:textSize="16sp" />
<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_below="@id/textView1"
android:ellipsize="end"
android:singleLine="true"
android:lines="1"
android:text="sayer1"
android:textSize="12sp" />
// if you want to align the latter text
// to the bottom, make a container as...
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
// declare the width/height of the TextView
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:text="sayer2"
android:textSize="16sp" />
<TextView
android:id="@+id/thirdLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_below="@+id/textView2"
android:text="state2"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
请告诉我这是否是预期的结果。希望这会有所帮助。
关于java - Android:为什么我的第二个 TextView 不显示,而第一个 TextView 却显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20662699/