Trouble with word wrapping
I am having trouble getting a screen to appear as I would like it to be
The code below shows two lines of textview's First line is just a date textview, below this are 3 textviews with some data in. On the right hand side I have a button and I wish to have it span over the two lines.
trouble is the 3 textviews could have data that push into the button and instead of word wrapping the text is either above the button or pushes the button off the screen
Could anyone help me solve this
Thanks for your time
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/border_small">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<!-- single date line -->
<TextView
android:text=" - "
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="@dimen/font_size_8"
android:layout_alignParentTop="true">
</TextView>
<!-- line under the date having 3 text fields -->
<TextView
android:text=" TEST TEXT TEXT "
andro开发者_StackOverflow社区id:id="@+id/round"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text_color_white"
android:textSize="@dimen/font_size_6"
android:layout_below="@id/date">
</TextView>
<TextView
android:text=" - "
android:id="@+id/spacer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text_color_white"
android:textSize="@dimen/font_size_6"
android:layout_toRightOf="@id/_round"
android:layout_below="@id/date">
</TextView>
<TextView
android:text=" TEST TEXT TEXT "
android:id="@+id/classification"
android:layout_toRightOf="@id/spacer1"
android:layout_below="@id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text_color_white"
android:textSize="@dimen/font_size_6">
</TextView>
<!-- button is on right hand side and spans both lines -->
<Button
android:text="@string/button_view"
android:layout_width="wrap_content"
android:id="@+id/button_details"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:textSize="@dimen/font_size_6"
android:layout_height="wrap_content">
</Button>
</RelativeLayout>
</LinearLayout>
Change the RelativeLayout
android:layout_width="match_parent"
One thing I noticed is that in your spacer1 TextView, you have this line: android:layout_toRightOf="@id/_round"
You have an extra underscore in there. That's not your problem, though. Wrap your date
, round
, and spacer1
TextViews in a Relative or Linear layout, and add the android:layout_toLeftOf="button_details"
attribute to it. Should fix your problem.
Try setting both android:layout_toRightOf and android:layout_toLeftOf on the text field(s) that need to use word wrap. So you might make the right-most TextView use this code:
<TextView
android:text=" TEST TEXT TEXT TEST TEXT TEXT TEST TEXT TEXT TEST TEXT TEXT TEST TEXT TEXT "
android:id="@+id/classification"
android:layout_toRightOf="@+id/spacer1"
android:layout_toLeftOf="@+id/button_details"
android:layout_below="@id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
精彩评论