Я пытаюсь создать вид списка, который выглядит следующим образом: альтернативный текст http://pici.se/pictures/hjFksZvLx.jpg
Он состоит из двух частей, левый выровнен по левому краю и содержит два текстовых представления, которые являются одной строкой и усечены,В правой части также есть два текстовых представления, но они выровнены по правому краю и имеют постоянный размер.Основная проблема в том, что правая часть не совпадает с правой.Если я использую статическую ширину, чтобы подтолкнуть ее вправо, она работает довольно хорошо, но тогда она не выглядит хорошо в ландшафтном режиме.
Я думал, что это должно быть просто сделать.Но это не так.
Сначала я попробовал с Linearlayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:orientation="vertical"
android:id="@+id/L1"
android:layout_height="fill_parent"
android:layout_weight="0.8"
android:layout_width="0dip">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:ellipsize="end"
android:scrollHorizontally="true"
android:text="Long text Long text Long text Long text Long text Long text Long text" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:ellipsize="end"
android:scrollHorizontally="true"
android:text="Short text" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:id="@+id/L2"
android:layout_gravity="top|right"
android:layout_height="fill_parent"
android:layout_weight="0.2"
android:layout_width="0dip">
<TextView
android:id="@+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="12:12" />
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="64%"
android:layout_gravity="right" />
</LinearLayout>
</LinearLayout>
Я возился со свойством веса, но, похоже, это не помогло.Правая часть вообще не выравнивается вправо.
А потом я попытался с Relativelayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView
android:id="@+id/text1"
android:layout_height="wrap_content"
android:lines="1"
android:scrollHorizontally="true"
android:layout_alignParentTop="true"
android:text="Long text Long text Long text Long text Long text Long text Long text"
android:layout_alignParentLeft="true"
android:ellipsize="end"
android:layout_width="275dp" />
<TextView
android:id="@+id/text2"
android:layout_height="wrap_content"
android:lines="1"
android:ellipsize="end"
android:scrollHorizontally="true"
android:text="Long text Long text Long text Long text Long text Long text Long text"
android:layout_below="@+id/text1"
android:layout_alignParentLeft="true"
android:layout_width="275dp" />
<TextView
android:id="@+id/text3"
android:layout_height="wrap_content"
android:text="12:12"
android:layout_gravity="right"
android:layout_alignParentRight="true"
android:layout_alignBaseline="@+id/text1"
android:layout_width="40dp"
android:layout_alignRight="@+id/text4" />
<TextView
android:id="@+id/text4"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="64%"
android:layout_alignParentRight="true"
android:layout_alignBaseline="@+id/text2"
android:layout_width="40dp" />
</RelativeLayout>
Та же проблема здесь, правая часть не выравнивается вправо должным образом, иЯ должен использовать статический размер Android: layout_width, чтобы подтолкнуть его на другую сторону.И если не использовать статический размер, текст начинает обрезать друг друга.