Я пытаюсь применить вес на андроиде LinearLayout
состоит из 3 элементов для TextView
, чтобы занять самое доступное пространство. Ориентация макета вертикальная, и я применяю weight="1"
на TextView
и не набираю вес на двух других элементах, чтобы заставить их располагаться в нижней части экрана. Однако это не работает, так как «большой» TextView
не занимает места вообще, а второй элемент LinearLayout
, который является Relativelayout
, занимает все пространство. Вот раскладка:Вес в LineraLayout с RelativeLayout ребенок не работает
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1" >
<TextView
android:id="@+id/txt_message"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:isScrollContainer="true"
android:maxLines="100000000" >
</TextView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/answer_panel"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@color/my_color"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:text="@string/answer_lbl">
</TextView>
<TextView
android:id="@+id/txt_answer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:isScrollContainer="true"
android:lines="6"
android:maxLines="100000000">
</TextView>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@color/my_color"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:layout_alignParentBottom="true"
android:gravity="center">
<Button android:id="@+id/my_button"
android:layout_height="wrap_content"
android:focusable="false"
android:layout_width="wrap_content"
android:background="@color/my_button"
android:textSize="14sp"
android:textColor="@color/background_color"
android:text="@string/txt_my_button"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Я пытался также embeed в txt_message TextView
в Linearlayout
, но это ничего не меняет. Как я могу поместить элементы в Relativelayout
в нижней части экрана и позволить первым TextView
занимать оставшееся пространство?
Я вижу только два элемента в корневой LinearLayout, в TextView и RelativeLayout, это правильно? –
Я вижу некоторые аномалии в этом макете. ** 1 ** - 'fill_parent' устарел с уровня API 8 (несколько лет назад) и заменен на' match_parent'. ** 2 ** - Я понимаю, что у вас нет четкого представления о том, как работают весы: должно быть больше, чем только один взвешенный вид в LinearLayout, или он полностью неэффективен. И weightSum полностью ** опционально **. –
Если высота LinearLayout соответствует match_parent и weightsum = 1, ваш первый элемент с весом = 1 должен занимать всю высоту linearlayout, т. Е. Всю высоту макета. –