I'm trying to create a listview item that consists of a textview and a button horizontally. I want the textview to be on the left and the button to be on the right. The button always has the same size so I want to let the textview take up the rest of the space.
My problem is that the textview (if it contains a text wider then the screen) pushes the button out of the screen.
I want the textview to not push the button out of the screen - I want the button to always stick to the right side of the screen regardless of how long the text in the textview is. If the text is too long to be displayed, I just want to display as much as possible (like overflow:hidden in HTML) without pushing the button out to the right.
Is it possible to configure my view to handle this or do I need to do al sorts of measuring of screen width and text length etc. etc.?
Here is my listview item xaml:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="0">
<TableRow>
<TextView
android:id="@+id/tv_item_text"
android:text="(123456) Item Name"
android:paddingLeft="10dip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:gravity="fill_vertical"
/>
<Button
android:id="@+id/btn_go"
android:layout_width="wrap_content"
android:text="Go"
android:textColor="@android:color/holo_blue_dark"
android:layout_gravity="fill_vertical"
android:gravity="center"
android:visibility="visible" />
</TableRow>
I'm pretty new to Xamarin so if anyone could help me out it would be much appreciated.
/Aidal
I really don't understand why people think using a TableLayout and nest a TableRow inside of it is a good practice for ListView/RecyclerView items...
Why are you not using a RelativeLayout which tells the button to be on the right and make the text view fill the rest of the space?
Should look something like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp">
<Button
android:id="@+id/btn_go"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Go"
android:textColor="@android:color/holo_blue_dark"
android:layout_alignParentRight="true" />
<TextView
android:id="@+id/tv_item_left"
android:layout_width="match_match"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/btn_go"
android:layout_alignParentLeft="true" />
</RelativeLayout>