I have a TextView left aligned and a right aligned button side by side. I want the button to take up as much space as it needs on the right (depending on the text that goes inside it) and the left text to fill as much as it can and ellipse at any overflow.
|Long title that may or may not ellipsi... <Button with text>|
I read and tried many other posts that seem to have similar problems, none of which worked for me. I tried using LinearLayout with weights, and also RelativeLayout with assigned layout_toLeftOf, none of which leads to what I need.
This is my LinearLayout code (with unnecessary details), where I give the left TextView layout_weight 1 and the layout_weight button of 0. This should give the right button all the necessary space and provide the TextView with the rest, but instead the left header stops displaying and the right button is smeared to the side and disconnects. I tried to replace the width of the text and the button with 0dip, as I said, that does not change anything.
<LinearLayout
android:layout_height="@dimen/title_bar_height"
android:layout_width="fill_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:layout_gravity="left|center_vertical"
android:gravity="left|center_vertical"
android:textSize="22sp"
android:lines="1"/>
<include layout="@layout/action_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"/>
</LinearLayout>
Replacing layout_weight in TextView with 0 actually allows the right button to fit completely on the screen, but the left text is still not displayed. If I have a layout_weights equal to 0 for a TextView and a button, and then change the width of the TextView from 0dip to wrap_content, everything appears, but instead the button is compressed to fill the remaining space (and the text inside is truncated).
Here is my attempt with RelativeLayout:
<RelativeLayout
android:layout_height="@dimen/title_bar_height"
android:layout_width="wrap_content">
<include layout="@layout/action_buttons"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@layout/action_buttons"
android:gravity="center_vertical"
android:scaleType="center"
android:textSize="22sp"
android:ellipsize="end"
android:lines="1"/>
</RelativeLayout>
, , TextView ( ) , . : layout_toLeftOf "@layout/action_buttons" , TextView ?
, , , , , . !