Возникли проблемы с получением простой RelativeLayout. Я строю ListView, состоящий из строк, которые должны выглядеть следующим образом:RelativeLayout и вертикальный делитель, выровненный по правому краю
+-----------------------------+--------------+
| Line 1 | Small button |
| Line 2, more text | |
| Line 3, even more text | |
Вот моя первая попытка - к сожалению, вертикальный разделитель не отображается.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="@+id/lineOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textColor="@color/wallet_holo_blue_light"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="@+id/lineTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/lineOne"
android:textSize="16dp" />
<TextView
android:id="@+id/lineThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/lineTwo"
android:textSize="14dp" />
<ImageButton
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@android:color/transparent"
android:focusable="false"
android:focusableInTouchMode="false"
android:onClick="doSomething"
android:src="@drawable/arrow_down" />
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_toLeftOf="@id/myButton"
android:background="?android:attr/listDivider" />
</RelativeLayout>
EDIT: Я почти решил свою собственную проблему с кодом ниже.
Теперь мой макет выглядит хорошо ...
+-----------------------------+--------------+
| Line 1 | Small button |
| Line 2, more text | |
| Line 3, even more text | |
... кроме случаев, когда первая линия, например, слишком долго - в таком случае делитель и кнопка не появляется:
+-----------------------------+--------------+
| Line 1, way way way way too long which |
| wraps |
| Line 2, more text |
| Line 3, even more text |
Не могли бы вы помочь мне внести окончательную корректировку?
Большое спасибо!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/lineOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/wallet_holo_blue_light"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="@+id/lineTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp" />
<TextView
android:id="@+id/lineThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp" />
</LinearLayout>
<!-- As per http://stackoverflow.com/questions/6992804/how-to-right-align-widget-in-horizontal-linear-layout-android -->
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal">
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="?android:attr/listDivider" />
<ImageButton
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="@drawable/arrow_down" />
</LinearLayout>
</LinearLayout>
Я просмотрел ваш файл, и все должно быть в порядке. Я просмотрел только предварительный просмотр, но в моем случае показан вертикальный делитель. Вы не видите разделителя в своем предварительном просмотре? Или это также только в предварительном просмотре? – mrtn
Вы также должны рассмотреть возможность установки 'layout_height'' wrap_content', поскольку они являются элементами списка. – mrtn
Спасибо, что посмотрели на это! Я вижу делитель в предварительном просмотре, но не на моем телефоне. – user3321335