Android CoordinatorLayout размещение Layout под другими

У меня есть CoordinatorLayout, и я хочу, чтобы FrameLayout был под всеми другими Layouts and widgets. Я пробовал использовать android:layout_below/above и app:layout_constraintVertical_bias = "0.0", но ни один из них не превосходит FrameLayout, чей android:id = "@+id/container".

Я думаю, что проще всего было бы поставить FrameLayout ниже других. Например в javascript есть Z-index.

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

Вот мой XML:

<?xml version = "1.0" encoding = "utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    xmlns:tools = "http://schemas.android.com/tools"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    xmlns:app = "http://schemas.android.com/apk/res-auto"
    tools:ignore = "ExtraText">

    <android.support.design.widget.AppBarLayout
        android:id = "@+id/app_bar"
        android:layout_width = "match_parent"
        android:layout_height = "54dp"
        android:layout_marginTop = "8dp"
        android:fitsSystemWindows = "true"
        android:theme = "@style/AppTheme.AppBarOverlay"
        app:layout_constraintBottom_toTopOf = "@+id/songTitle"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintHorizontal_bias = "0.0"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toTopOf = "@+id/container"
        app:layout_constraintVertical_bias = "0.025">

        <android.support.v7.widget.Toolbar
            android:id = "@+id/toolbar"
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            android:layout_alignParentTop = "true"
            android:elevation = "6dp"
            android:theme = "@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme = "@style/ThemeOverlay.AppCompat.Light">

            <Button
                android:id = "@+id/backToSongList"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:text = "Song List" />

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

    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.CoordinatorLayout
        android:id = "@+id/gameBoard"
        android:layout_width = "match_parent"
        android:layout_height = "132dp"
        android:layout_alignParentStart = "true"
        android:layout_marginBottom = "8dp"
        app:layout_constraintBottom_toTopOf = "@+id/songTitle"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintHorizontal_bias = "1.0"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toBottomOf = "@+id/app_bar"
        app:layout_constraintVertical_bias = "0.0">

        <com.jjoe64.graphview.GraphView
            android:id = "@+id/graph"
            android:layout_width = "match_parent"
            android:layout_height = "match_parent" />

    </android.support.design.widget.CoordinatorLayout>


    <ImageButton
        android:id = "@+id/playRecord"
        android:layout_width = "70dp"
        android:layout_height = "75dp"

        android:layout_above = "@id/container"
        android:layout_marginBottom = "8dp"
        android:layout_marginEnd = "8dp"
        android:layout_marginStart = "8dp"
        app:layout_constraintBottom_toBottomOf = "parent"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintStart_toStartOf = "parent"
        app:srcCompat = "@android:drawable/star_big_on"
        app:layout_constraintVertical_bias = "0.0"/>

    <TextView
        android:id = "@+id/pitchText"
        android:layout_width = "113dp"
        android:layout_height = "50dp"
        android:layout_marginBottom = "8dp"
        android:layout_marginEnd = "8dp"
        android:layout_marginStart = "8dp"
        android:layout_marginTop = "8dp"
        android:textSize = "24sp"
        app:layout_constraintBottom_toBottomOf = "@+id/playRecord"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintHorizontal_bias = "0.724"
        app:layout_constraintStart_toEndOf = "@+id/playRecord"
        app:layout_constraintTop_toBottomOf = "@+id/songTitle"
        app:layout_constraintVertical_bias = "0.0" />

    <TextView
        android:id = "@+id/songTitle"
        android:layout_width = "380dp"
        android:layout_height = "61dp"
        android:layout_above = "@id/container"
        android:layout_marginBottom = "12dp"
        android:layout_marginEnd = "8dp"
        android:text = "TextView"
        android:textColor = "@android:color/background_dark"
        android:textSize = "24sp"
        android:textStyle = "bold|italic"
        app:layout_constraintBottom_toTopOf = "@+id/playRecord"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintHorizontal_bias = "0.0"
        app:layout_constraintVertical_bias = "0.0"
        app:layout_constraintStart_toStartOf = "parent" />

    <FrameLayout xmlns:android = "http://schemas.android.com/apk/res/android"
        xmlns:tools = "http://schemas.android.com/tools"
        android:id = "@+id/container"
        android:layout_width = "391dp"
        android:layout_height = "569dp"
        android:background = "#000"
        app:layout_constraintBottom_toBottomOf = "parent"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintHorizontal_bias = "0.0"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toTopOf = "parent"
        app:layout_constraintVertical_bias = "1.0"
        tools:context = "com.example.richard.smarttabs.SongPlayer" />


</android.support.constraint.ConstraintLayout>

Так как я учусь, все комментарии о моем стиле также приветствуются!

Обновлено: Я заставил его работать, и код выглядит так:

<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    xmlns:tools = "http://schemas.android.com/tools"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    xmlns:app = "http://schemas.android.com/apk/res-auto"
    tools:ignore = "ExtraText">


    <FrameLayout xmlns:android = "http://schemas.android.com/apk/res/android"
        xmlns:tools = "http://schemas.android.com/tools"
        android:id = "@+id/container"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        android:layout_alignParentStart = "true"
        android:layout_alignParentTop = "true"
        android:background = "#000"
        tools:context = "com.example.richard.smarttabs.SongPlayer" />

    <android.support.design.widget.AppBarLayout
        android:id = "@+id/app_bar"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:background = "@color/colorPrimary"
        android:fitsSystemWindows = "true"
        android:theme = "@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id = "@+id/toolbar"
            android:layout_width = "match_parent"
            android:layout_height = "match_parent"
            android:layout_alignParentTop = "true"
            android:elevation = "6dp"
            android:theme = "@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme = "@style/ThemeOverlay.AppCompat.Light">

            <Button
                android:id = "@+id/backToSongList"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:text = "Song List" />

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

    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.CoordinatorLayout
        android:id = "@+id/gameBoard"
        android:layout_width = "match_parent"
        android:layout_height = "138dp"
        android:layout_alignParentLeft = "true"
        android:layout_below = "@+id/app_bar"
        android:layout_marginBottom = "8dp"
        android:background = "#c1c1c1"
        android:alpha = "0.4">

        <com.jjoe64.graphview.GraphView
            android:id = "@+id/graph"
            android:layout_width = "match_parent"
            android:layout_height = "match_parent" />

    </android.support.design.widget.CoordinatorLayout>


    <ImageButton
        android:id = "@+id/playRecord"
        android:layout_width = "70dp"
        android:layout_height = "75dp"
        android:layout_alignParentBottom = "true"
        android:layout_centerHorizontal = "true"
        android:layout_marginBottom = "21dp"
        android:background = "#fff"
        android:src = "@mipmap/ic_launcher"
        android:alpha = "0.5"/>

    <TextView
        android:id = "@+id/pitchText"
        android:layout_width = "84dp"
        android:layout_height = "58dp"
        android:layout_alignParentBottom = "true"
        android:layout_alignParentEnd = "true"
        android:layout_marginBottom = "30dp"
        android:layout_marginEnd = "21dp"
        android:layout_marginStart = "20dp"
        android:alpha = "0.5"
        android:textColor = "#fff"
        android:textSize = "24sp" />

    <TextView
        android:id = "@+id/songTitle"
        android:layout_width = "380dp"
        android:layout_height = "77dp"
        android:layout_alignParentBottom = "true"
        android:layout_alignParentStart = "true"
        android:layout_marginBottom = "120dp"
        android:alpha = "0.5"
        android:background = "#918c8c"
        android:text = "TextView"
        android:textColor = "#b3b3"
        android:textSize = "24sp"
        android:textStyle = "bold|italic" />


</RelativeLayout>

Я бы посоветовал вам вместо этого использовать LinearLayout внутри Relative Layout.

Deepak kaku 18.04.2018 01:33
0
1
406
1

Ответы 1

Может, можно попробовать это?

<?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 = "match_parent"
   >

 <android.support.design.widget.AppBarLayout
        android:id = "@+id/app_bar"
        android:layout_width = "match_parent"
        android:layout_height = "54dp"
        android:layout_marginTop = "8dp"
        android:fitsSystemWindows = "true"
        android:theme = "@style/AppTheme.AppBarOverlay"
        app:layout_constraintBottom_toTopOf = "@+id/songTitle"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintHorizontal_bias = "0.0"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toTopOf = "@+id/container"
        app:layout_constraintVertical_bias = "0.025">

        <android.support.v7.widget.Toolbar
            android:id = "@+id/toolbar"
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            android:layout_alignParentTop = "true"
            android:elevation = "6dp"
            android:theme = "@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme = "@style/ThemeOverlay.AppCompat.Light">

            <Button
                android:id = "@+id/backToSongList"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:text = "Song List" />

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

    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.CoordinatorLayout
        android:id = "@+id/gameBoard"
        android:layout_width = "match_parent"
        android:layout_height = "132dp"
        android:layout_alignParentStart = "true"
        android:layout_marginBottom = "8dp"
        app:layout_constraintBottom_toTopOf = "@+id/songTitle"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintHorizontal_bias = "1.0"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toBottomOf = "@+id/app_bar"
        app:layout_constraintVertical_bias = "0.0">

        <com.jjoe64.graphview.GraphView
            android:id = "@+id/graph"
            android:layout_width = "match_parent"
            android:layout_height = "match_parent" />

    </android.support.design.widget.CoordinatorLayout>


    <ImageButton
        android:id = "@+id/playRecord"
        android:layout_width = "70dp"
        android:layout_height = "75dp"

        android:layout_above = "@id/container"
        android:layout_marginBottom = "8dp"
        android:layout_marginEnd = "8dp"
        android:layout_marginStart = "8dp"
        app:layout_constraintBottom_toBottomOf = "parent"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintStart_toStartOf = "parent"
        app:srcCompat = "@android:drawable/star_big_on"
        app:layout_constraintVertical_bias = "0.0"/>

    <TextView
        android:id = "@+id/pitchText"
        android:layout_width = "113dp"
        android:layout_height = "50dp"
        android:layout_marginBottom = "8dp"
        android:layout_marginEnd = "8dp"
        android:layout_marginStart = "8dp"
        android:layout_marginTop = "8dp"
        android:textSize = "24sp"
        app:layout_constraintBottom_toBottomOf = "@+id/playRecord"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintHorizontal_bias = "0.724"
        app:layout_constraintStart_toEndOf = "@+id/playRecord"
        app:layout_constraintTop_toBottomOf = "@+id/songTitle"
        app:layout_constraintVertical_bias = "0.0" />

    <TextView
        android:id = "@+id/songTitle"
        android:layout_width = "380dp"
        android:layout_height = "61dp"
        android:layout_above = "@id/container"
        android:layout_marginBottom = "12dp"
        android:layout_marginEnd = "8dp"
        android:text = "TextView"
        android:textColor = "@android:color/background_dark"
        android:textSize = "24sp"
        android:textStyle = "bold|italic"
        app:layout_constraintBottom_toTopOf = "@+id/playRecord"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintHorizontal_bias = "0.0"
        app:layout_constraintVertical_bias = "0.0"
        app:layout_constraintStart_toStartOf = "parent" />
    <LinearLayout
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:layout_alignParentBottom = "true" >
    <FrameLayout xmlns:android = "http://schemas.android.com/apk/res/android"
        xmlns:tools = "http://schemas.android.com/tools"
        android:id = "@+id/container"
        android:layout_width = "391dp"
        android:layout_height = "569dp"
        android:background = "#000"
        app:layout_constraintBottom_toBottomOf = "parent"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintHorizontal_bias = "0.0"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toTopOf = "parent"
        app:layout_constraintVertical_bias = "1.0"
        tools:context = "com.example.richard.smarttabs.SongPlayer" />

       </LinearLayout>
</RelativeLayout>

Обратите внимание: я просто скопировал ваш xml, поэтому некоторые атрибуты вам, возможно, придется изменить или удалить. Android Studio может помочь в этом

Я попробовал, изменил все, чтобы он подошел, но макет все еще был на высоте.

kataroty 18.04.2018 01:54

не могли бы вы приложить скриншот? Спасибо

Deepak kaku 18.04.2018 18:57

Круто, рад знать

Deepak kaku 18.04.2018 22:18

Другие вопросы по теме