如何在框架布局中设置图像
how to set image inside framelayout
我想在 FrameLayout
中设置图像,但与框架布局的背景重叠
这是实现您想要的目标的一种方法
<FrameLayout>
<ImageView>
<- Your background image with width and height to match parent ->
<ImageView>
<-this is where you put your image->
</FrameLayout>
这是示例,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 >
我想在 FrameLayout
中设置图像,但与框架布局的背景重叠
这是实现您想要的目标的一种方法
<FrameLayout>
<ImageView>
<- Your background image with width and height to match parent ->
<ImageView>
<-this is where you put your image->
</FrameLayout>
这是示例,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 >