java - Linear Layout Wrapping TextView -


i designing layout following

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content" >      <textview         android:id="@+id/messagetext"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_weight="1"         android:text="some long text asd asd asd asd asd asd asd asd asd asd asd![enter image description here][1]" />      <button         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="12:45 pm" />  </linearlayout> 

it gives ui above... long text image

which perfect need. long text getting wrapped without pushing button away screen orientation horizontal. button not stretching.

but if text small. looks

short text image

what want button should aligned left end of text this

short correct text

i know put layout weight 1.

it consumes whole area left after giving needed space button.

if don't put that. , make width wrap content. works great short text. text grows.

it pushes button away screen.

thats problem. hope made problem enough descriptive. of course long read. painful of course. glad know pointer.

i not reluctant use relative layout well.

any appreciated.

thanks

hope works you. please try this:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" >  <textview     android:id="@+id/messagetext"     android:layout_width="0dp"     android:layout_height="wrap_content"     android:layout_weight="1"     android:text="some long text asd asd asd asd asd asd asd asd asd asd asd![enter image description here][1]" />  <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="12:45 pm" /> 

i think need change android:layout_width="fill_parent" of linearlayout android:layout_width="wrap_content"


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -