I'm trying to get a TextView to wrap it's text over multiple lines, but it always just seems to get chopped off at the end of the first line. Here's the relevant XML from my view:
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/relExtraInfo"
android:layout_below="@+id/titleContainerLayout">
<RelativeLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" android:layout_below="@+id/titleArtwork"
android:id="@+id/relStarring">
<TextView android:textStyle="bold" android:layout_height="wrap_content"
android:text="Starring:" android:layout_width="wrap_content"
android:id="@+id/lblStarring" android:layout_alignParentLeft="true"></TextView>
<TextView android:layout_alignTop="@+id/lblStarring"
android:text="This is a very long peice of text to try and get the TextView to spill over multiple lines."
android:layout_alignBottom="@+id/lblStarring" android:id="@+id/txtStarring"
android:layout_toRightOf="@+id/lblStarring" android:layout_width="fill_parent"></TextView>
</RelativeLayout>
<RelativeLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/relDirector"
android:layout_below="@+id/relStarring">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_alignParentLeft="true"
android:text="Director:" android:textStyle="bold" android:id="开发者_开发百科@+id/lblDirector"></TextView>
<TextView android:layout_height="wrap_content"
android:text="TextView" android:layout_width="wrap_content"
android:layout_alignTop="@+id/txtDirector"
android:layout_alignBottom="@+id/txtDirector" android:id="@+id/txtDirector"
android:layout_toRightOf="@+id/lblDirector" android:ellipsize="none"></TextView>
</RelativeLayout>
</RelativeLayout>
I've tried various things to make it wrap, I've set elipsize to none, scrollHorizontally to false, I've even tried the deprecated singleLine = false, and that doesn't work.
There seems to be a lack of examples showing how to do this, and numerous people on SO asking the same question, none of which have a definitive answer.
So the answer is that RelativeLayout & multiline TextView don't play nice together, change the 2 inner RelativeLayout elements to LinearLayout and the TextView's suddenly have multiple lines.
Try to add android:width="0dip"
in th TextView
.
精彩评论