问题
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 theandroid:layout_gravity
attribute along with whateverandroid:padding
andandroid: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