Я сталкиваюсь с проблемой рисования вертикальной линии внутри относительного макета в виде макета элемента списка следующим образом:
высота макета изменяется от элемента к элементу, вот код:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">
<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="3dip"
android:layout_marginTop="3dip"
android:text="Button"></Button>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:text="TextView"></TextView>
<TextView android:id="@+id/expandable_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_toRightOf="@+id/button1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black"
android:text="Some expandable text"></TextView>
<View android:id="@+id/vertical_line"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="4dip"
android:background="@color/orange"/>
</RelativeLayout>
Проблема в том, что вертикальная линия не видна / не работает, есть предложения?
Заранее спасибо!
p.s
обратите внимание, что эта проблема была решена при работе с LinearLayout, но у меня были проблемы с производительностью из-за вложенных представлений в макете, и единственное решение заключается в использовании RelativeLayout, также строки TextViews меняются от элемента к элементу.
Решение № 1
После поиска и использования предложенных ответов, опубликованных здесь (спасибо ..)
Я нашел решение, , которое кажется довольно уродливым , но из-за проблем с заполнением
RelativeLayout, использующий высоту «fill_parent», в то время как сама высота макета устанавливается на «wrap_content», кажется разумным вариантом.
Идея состоит в том, чтобы взять самый верхний вид (кнопка) и самый нижний вид (расширяемый текст) и использовать их в качестве привязок для выравнивания по высоте вертикальной линии.
как вы можете видеть в этом коде:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">
<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:paddingTop="3dip"
android:layout_marginTop="3dip"
android:text="Button"></Button>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:paddingTop="3dip"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:text="TextView"></TextView>
<TextView android:id="@+id/expandable_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_toRightOf="@+id/button1"
android:paddingBottom="10dip"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black"
android:text="Some expandable text"></TextView>
<View android:id="@+id/vertical_line"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/list_item_task_statusbutton"
android:layout_alignBottom="@id/list_item_task_description"
android:layout_marginRight="4dip"
android:background="@color/orange"/>
</RelativeLayout>
Обратите внимание на изменения в представлениях, особенно на замену "android: marginXXXX = value"
с "android: paddingXXXX = value" для фиксации позиций видов.
Спасибо .. и хорошего дня!