I have a TextView and an ImageView in Relative Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingLeft="10dip" android:id="@+id/itemRoot"
android:clickable="false">
<TextView android:layout_width="wrap_content" android:text="TextView"
android:layout_height="wrap_content" android:id="@+id/itemTxt"
android:layout_alignParentLeft="true" android:layout_centerVertical="true"
android:singleLine="true"></TextView>
<ImageView android:id="@+id/delBtn" android:layout_height="wrap_content"
android:src="@drawable/delete" android:layout_width="wrap_content"
android:layout_alignParentRight="true" android:paddingRight="10dip"
android:layout_centerVertical="true"></ImageView>
</RelativeLayout>
However, when text gets too long it overlaps with the ImageView goes under it all the way to the end of the screen and then “…”. But I want it to stop where ImageView begins. I can’t stretch the TextView all the way to ImageView because I also have some backgrounds underneath that look ugly. So I tried adding a blank, transparent spacer between the 2 Views:
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/spacer"
android:layout_alignTop="@+id/itemTxt" android:layout_alignBottom="@+id/itemTxt"
android:layout_toLeftOf="@+id/delBtn" android:layout_toRightOf="@+id/itemTxt"
android:minWidth="5dip" android:background="@android:color/transparent"></TextView>
However, I still have the same problem. The spacer works nicely as long as text is not too long. But because itemTxt defined with respect to the ParentLeft it just pushes the spacer out of the screen, and I can’t define it also with respect to the spacer as SDK complains that it is circular.
Any thoughts?
Alex
Is this what your looking for?
Keeps the textview above the Imageview:
Or do you mean next to each other?
Use a Linear Layout: