Как разместить элементы друг над другом в FrameLayout? - PullRequest
0 голосов
/ 10 апреля 2019

Я использую FrameLayout в моем макете и кнопки отображаются в первую очередь LinearLayout.Я хочу отобразить эту кнопку под первым LinearLayout и не изменять FrameLayout на LinearLayout или RelativeLayout.Является ли это возможным?Не найдено никакого решения, только для изменения FrameLayout на LinearLayout или RelativeLayout.

Вот как это выглядит сейчас: Снимок экрана

Этомой код xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    android:id="@id/menu_container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    style="@style/LeftDrawer"
    xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
    android:id="@id/menu_user_profile"
    android:clickable="true"
    android:focusable="true"
    style="@style/MenuTopBox">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="@dimen/activity_margin_horizontal"
        android:layout_weight="1.0">
        <ImageView
            android:id="@id/menu_avatar"
            android:background="@color/transparent"
            android:layout_width="@dimen/avatar_default_size"
            android:layout_height="@dimen/avatar_default_size"
            android:src="@drawable/ic_default_avatar"
            android:scaleType="fitCenter" />
        <ImageView
            android:id="@id/menu_avatar_photo"
            android:background="@color/transparent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_logo_camera"
            android:scaleType="fitCenter"
            android:layout_alignBottom="@id/menu_avatar"
            android:layout_alignParentRight="true" />
    </RelativeLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.5">
        <TextView
            android:gravity="center_vertical"
            android:id="@id/menu_profile"
            android:layout_height="fill_parent"
            android:layout_marginLeft="@dimen/activity_margin_horizontal"
            android:layout_marginRight="@dimen/margin_micro"
            android:text="@string/menu_profile"
            android:textColor="@color/white"
            style="@style/TextBig" />
    </LinearLayout>
</LinearLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@id/menu_logout_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/menu_logout_button"
        android:drawableLeft="@drawable/ic_menu_logout"
        style="@style/ButtonMenu" />
</LinearLayout>
</FrameLayout>

1 Ответ

0 голосов
/ 10 апреля 2019

Ваш макет содержит много вложенных представлений, это может привести к тому, что ваш макет будет работать медленнее и выполнять больше вычислений, чем нужно.

Я могу порекомендовать использовать ConstraintLayout .

Но почему - это простой макет, предназначенный для оптимизации и выравнивания иерархии представлений ваших макетов (то есть без вложенных представлений), что ускоряет время загрузки вашего макета.

Кроме того, constraintLayout сэкономит вам много времени , потому что сделать макет с ним действительно легко и просто.

Вот пример макета, который выглядит так, как вы хотитек использованию constraintLayout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">


<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="Button"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/textView8"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:text="text"
    android:textSize="18sp"
    app:layout_constraintBottom_toBottomOf="@+id/button3"
    app:layout_constraintStart_toEndOf="@+id/button3"
    app:layout_constraintTop_toTopOf="@+id/button3" />

<Button
    android:id="@+id/button4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:text="Button"
    app:layout_constraintEnd_toEndOf="@+id/button3"
    app:layout_constraintStart_toStartOf="@+id/button3"
    app:layout_constraintTop_toBottomOf="@+id/button3" />

<Button
    android:id="@+id/button5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:text="camera"
    app:layout_constraintBottom_toBottomOf="@+id/button4"
    app:layout_constraintStart_toEndOf="@+id/button4"
    app:layout_constraintTop_toTopOf="@+id/button4" />
</androidx.constraintlayout.widget.ConstraintLayout>
...