My question might be, \"How does one create a single-line horizontal LinearLayout with two single-line non-wrapping TextViews, where the left TextView always occupies 1/3 of
hackbod presents another good-looking argument as to why ListViews cannot layout rows like TableViews in an answer to the question Does Android have a Table like Adapter for ListView.
The best I can come up with is to have a row.xml that looks something like this. It's not ideal, but it will keep the rows with a fixed width, which will scale on a change of dimensions, but not based off of the text. It'll give you 80% of a Table Layout, with the benefits of a ListView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:gravity="left|center"
android:layout_width="wrap_content"
android:paddingBottom="10px"
android:paddingTop="10px"
android:paddingLeft="3px">
<TextView
android:id="@+id/TextView01"
android:layout_width="0dp"
android:layout_weight=1
android:layout_height="wrap_content"
android:gravity="left"
android:singleLine="true"
android:textSize="15dip"
android:textStyle="bold"
android:textColor="#d08021"
android:paddingLeft="20dip">
</TextView>
<TextView
android:id="@+id/TextView02"
android:layout_width="0dp"
android:layout_weight=3
android:layout_height="wrap_content"
android:gravity="left"
android:singleLine="true"
android:layout_marginLeft="10dip"
android:textSize="15dip"
android:textStyle="bold"
android:textColor="#7f0000">
</TextView>
</LinearLayout>
You can use TableLayout
and make it to behave like ListView
(at least visually). Here is my answer.
I think this tutorial will help you. Try this..
Your row.xml should look like :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:gravity="left|center"
android:layout_width="wrap_content"
android:paddingBottom="10px"
android:paddingTop="10px"
android:paddingLeft="3px">
<TextView
android:id="@+id/TextView01"
android:layout_width="70dip"
android:layout_height="wrap_content"
android:gravity="left"
android:singleLine="true"
android:textSize="15dip"
android:textStyle="bold"
android:textColor="#d08021"
android:paddingLeft="20dip">
</TextView>
<TextView
android:id="@+id/TextView02"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:gravity="left"
android:singleLine="true"
android:layout_marginLeft="10dip"
android:textSize="15dip"
android:textStyle="bold"
android:textColor="#7f0000">
</TextView>
</LinearLayout>
You need this type of layout right ? Correct me if i am not wrong.