在 android 中的现有图像视图上添加视图

add view on existing imageview in android

我想用另一个只有黑色背景的视图覆盖现有的图像视图,我希望它的大小等于图像视图,但高度不能正常工作

这是我的代码:

<RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#000" >

                    <ImageView
                        android:id="@+id/feedImage"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:adjustViewBounds="true"
                        android:scaleType="fitXY"
                        android:src="@drawable/cover" />

                    <RelativeLayout
                        android:id="@+id/playBackground"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:layout_centerInParent="true"                        
                        android:background="#75000000" >

                        <ImageView
                            android:id="@+id/playIcon"
                            android:layout_width="110dp"
                            android:layout_height="110dp"
                            android:layout_centerInParent="true"
                            android:adjustViewBounds="true"
                            android:scaleType="fitXY"
                            android:src="@drawable/play" />
                    </RelativeLayout>
                </RelativeLayout>

这就是结果:

在你的第二个 ImageView 中将你的 layout_height 和你的 layout_width 更改为 match_parent值。

<FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#000" >

                <ImageView
                    android:id="@+id/feedImage"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:adjustViewBounds="true"
                    android:scaleType="fitXY"
                    android:src="@drawable/cover" />

                <RelativeLayout
                    android:id="@+id/playBackground"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_centerInParent="true"                        
                    android:background="#75000000" >

                    <ImageView
                        android:id="@+id/playIcon"
                        android:layout_width="110dp"
                        android:layout_height="110dp"
                        android:layout_centerInParent="true"
                        android:adjustViewBounds="true"
                        android:scaleType="fitXY"
                        android:src="@drawable/play" />
                </RelativeLayout>
            </FrameLayout>