Search code examples
androidxmlandroid-studiooverlappingandroid-framelayout

how to set image inside framelayout


I want to set image inside the FrameLayout but is overlapping the framelayout's background

right now how its looking


Solution

  • This is sample example, https://snag.gy/IrawbT.jpg

    item last put on the stack will be drawn on top of the items below it. This layout makes it very easy to draw on top of other layouts, especially for tasks such as button placement.

    To arrange the children inside of a FrameLayout use the android:layout_gravity attribute along with whatever android:padding and android:margin you need.

    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/frame_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <!-- Child1 is drawn first -->
        <!-- Child2 is drawn over Child1 -->
        <!-- Child3 is drawn over Child1 and Child2 -->
        <TextView
            android:id="@+id/child1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:text="Child 3"
            android:textSize="25sp"
            android:textStyle="bold" />
    
        <ImageView
            android:id="@+id/child2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_margin="40dip"
            android:src="@color/childs"
            android:text="Child 2" />
    
        <ImageView
            android:id="@+id/child3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="Image"
            android:src="@color/_dark_gray" />
    </FrameLayout >