how to set image inside framelayout

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-15 09:58:48

问题


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


回答1:


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 >



回答2:


this is one way to achieve what you want

<FrameLayout>

    <ImageView>
    <-this is where you put your image->


    <ImageView>
    <- Your background image with width and height to match parent ->

</FrameLayout>


来源:https://stackoverflow.com/questions/39724430/how-to-set-image-inside-framelayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!