Search code examples
androidimageviewcover

add view on existing imageview in android


I want to cover existing imageview with another view which just has black background and i want its size to be equal to the imageview but the height doesn't work properly

That's my code :

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

That's the result :

enter image description here


Solution

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