I am designing a layout as 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 really long text asd asd asd asd asd asd asd asd asd asd asd" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12:45 PM" />
</LinearLayout>
It gives a UI like the above...
Which is perfect what i need. Long text is getting wrapped properly without pushing Button away from the screen as orientation is horizontal. button is also not stretching.
But if text is small. It looks like this
What i want is Button should be aligned to the left end of the text like this
I know as i put the layout weight to 1.
It consumes the whole area left after giving needed space to the button.
If i don't put that. and make the width to be wrap content. It works great for short text. but as text grows.
it pushes the button away from the screen.
Thats the problem. Hope i made my problem enough descriptive. But of course long to read. Painful of course. But will be really glad to know any pointer.
I am not reluctant to use relative layout as well.
Any help will be appreciated.
Thanks
Hope this works for 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 really 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 you need to change android:layout_width="fill_parent" of linearlayout to android:layout_width="wrap_content"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With