约束布局中的前景重叠

问题描述 投票:0回答:1

我有两个约束布局嵌套在另一个约束布局中。我已经为父约束布局设置了前景图像,但图像与其他两个布局重叠,如您在 image

中看到的那样

我在网上搜索过但找不到如何解决这个问题

这是我到目前为止的 xml 文件:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    android:forceHasOverlappingRendering="false"
    android:foreground="@drawable/deviworkslogo_only_gears_white"
    android:foregroundGravity="center"
    android:foregroundTint="#E6E6E6"
    android:foregroundTintMode="src_in">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/constraintLayout"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:background="#D31212"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <Button
            android:id="@+id/homeBtn"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginEnd="30dp"
            android:foreground="@drawable/ic_home_black_24dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/libraryBtn"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:id="@+id/libraryBtn"
            android:layout_width="60dp"
            android:layout_height="60dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:id="@+id/settingsBtn"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginStart="30dp"
            android:foreground="@drawable/ic_settings_black_24dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toEndOf="@+id/libraryBtn"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="250dp"
        android:layout_height="0dp"
        android:background="#3973AF"
        app:layout_constraintBottom_toTopOf="@+id/constraintLayout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

我想要获得的是前景图像保留在嵌套约束布局后面

android android-constraintlayout
1个回答
0
投票

如果您希望图像保留在嵌套的

ConstraintLayout
后面,您可能需要使用
android:background
属性而不是
android:foreground

在您提供的代码中,在父级

ConstraintLayout
中,您有以下行:

android:foreground="@drawable/deviworkslogo_only_gears_white"

如果您希望图像位于嵌套的 ConstraintLayouts 后面,则需要切换到使用 background 而不是

foreground

android:foreground
属性的快速描述中我们可以读到以下内容: “定义在内容上绘制的可绘制对象。这可以用作覆盖。如果重力设置为填充,则前景可绘制对象参与内容的填充。

© www.soinside.com 2019 - 2024. All rights reserved.