How to align Button to the right, without being overlapped by TextView?
Posted
by Kilnr
on Stack Overflow
See other posts from Stack Overflow
or by Kilnr
Published on 2010-04-27T11:30:53Z
Indexed on
2010/04/27
11:33 UTC
Read the original article
Hit count: 247
Hello,
I'm trying to get something like this: http://img202.imageshack.us/img202/552/layoutoy.png. I'm using this as a list item (technically as the group view of an ExpandableListView).
Here's the XML file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight">
<TextView
android:id="@+id/list_item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end" />
<Button
android:id="@+id/list_item_button"
android:text="Click me!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/list_item_text" />
</RelativeLayout>
But this doesn't work. The Button doesn't wrap its contents, instead it uses all available horizontal space. The TextView does wrap its contents, but what I want it to do is to cut off when it overlaps the Button.
In other words, I want all the buttons to be of the same width, regardless of the amount of text in the textviews. Is this at all possible?
© Stack Overflow or respective owner