0

Хочу отрисовать на экране 4 элемента. Использую для этого LinearLayout, проблема в том, что мне нужно что бы 3 из них имели высоту wrap_content, а 1 match_parent. Все вроде как просто, но у меня почему-то творится какая-то вакханалия на экране, когда я пытаюсь затестить наработки. Ниже приведу код xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:clickable="true"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical"
    android:clickable="true">

    <ImageView
        android:id="@+id/preview"
        android:layout_width="match_parent"
        android:layout_height="260dp"
        android:layout_margin="5dp"
        android:visibility="visible"
        app:srcCompat="@drawable/details_view" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/title"
            android:layout_width="225dp"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:text="food Name" />

        <TextView
            android:id="@+id/description"
            android:layout_width="225dp"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/title"
            android:text="Food description" />

        <TextView
            android:id="@+id/price"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/description"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:layout_marginEnd="45dp"
            android:text="Price" />

        <TextView
            android:id="@+id/additions"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/description"
            android:layout_marginTop="11dp"
            android:text="More " />
    </RelativeLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/addition_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </android.support.v7.widget.RecyclerView>

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:text="Add to order" />

</LinearLayout>
</FrameLayout>
1
  • не помешает какая то схема, как все должно выглядеть на экране.
    – pavlofff
    20 июн 2017 в 22:54

1 ответ 1

1

В вашем Relative Layout позиционируйте элементы в Preview режиме, то есть переносите нужные View элементы на экран и расставляйте их как надо. Или попробуйте Relative Layout заменить на Linear Layout с нужной вам ориентацией Vertical || Horizontal и далее позиционируйте по весу:

android:layout_width="0dp"
android:layout_weight="1"

В первых трех view элементах, а четвертый match_parent. Или же

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.