Android CoordinatorLayout将Layout放置在其他人之下

时间:2018-04-17 23:25:34

标签: android xml layout android-coordinatorlayout

我有一个CoordinatorLayout,我希望FrameLayout位于所有其他Layouts and widgets之下。我尝试过使用android:layout_below/aboveapp:layout_constraintVertical_bias="0.0",但都没有超过FrameLayout的{​​{1}}。

我认为最简单的方法是将android:id="@+id/container"置于其他人之下。例如,在javascript中有FrameLayout

我不确定但也许同样重要的是要注意Z-index将包含来自相机的预览,而FrameLayout就在它之上,即使我不改变任何东西。

这是我的XML:

AppBarLayout

由于我正在学习,所有关于我风格的评论也欢迎!

编辑:我让它工作,代码看起来像这样:

<?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>

1 个答案:

答案 0 :(得分: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可以提供帮助