图片隐藏在按钮下 android

Image hiding under button android

图像视图隐藏在按钮下面 我可以做些什么更改,以便图像视图可以在按钮视图寻呼机上方也有底部填充,以便按钮可以适当容纳。图片显示在其他部分,但不在按钮上方。

  <?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"
        android:orientation="vertical"
        tools:context=".McqActivity"
        android:id="@+id/fragment"
        >
    
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent">
    
    
                <ImageView
                android:id="@+id/starFirst"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:src="@drawable/ic_baseline_star_24"
                />                  
    
    
            <com.google.android.material.button.MaterialButton
                android:id="@+id/right"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                 />
    
        </RelativeLayout>
    
        <androidx.viewpager2.widget.ViewPager2
            android:id="@+id/questions_view_frag"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            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="0.0"
            android:orientation="horizontal"
            android:paddingBottom="20dp"
            android:paddingTop="50dp"
            >
    
        </androidx.viewpager2.widget.ViewPager2>
        
    
    </androidx.constraintlayout.widget.ConstraintLayout>

layout_constraintBottom_toBottomOf 和其他 layout_constraint... 不会在 RelativeLayout 内工作,这些需要与 ConstraintLayout 作为严格父级一起工作。如果你想在 RelativeLayoyut 内对齐两个 Views next to/below/above 你必须使用其他属性,例如

android:layout_below="@+id/starFirst"
android:layout_above="@+id/starFirst"
android:layout_toRightOf="@id/starFirst"
android:layout_toLeftOf="@id/starFirst"

请注意,每个以 layout_ 开头的属性都希望由严格的父级读取,而不是设置了此类属性的 View 读取。每个ViewGroup都有自己的一组这样

编辑:原来这是一个elevationcase/issue(Z轴),所以有用的属性是

android:translationZ="100dp"
android:elevation="100dp"