Android 如何在framelayout内设置图像
我想在Android 如何在framelayout内设置图像,android,xml,android-studio,overlapping,android-framelayout,Android,Xml,Android Studio,Overlapping,Android Framelayout,我想在FrameLayout内设置图像,但图像与FrameLayout的背景重叠 这是实现您想要的目标的一种方法 <FrameLayout> <ImageView> <- Your background image with width and height to match parent -> <ImageView> <-this is where you put your image-> <
FrameLayout
内设置图像,但图像与FrameLayout的背景重叠
这是实现您想要的目标的一种方法
<FrameLayout>
<ImageView>
<- Your background image with width and height to match parent ->
<ImageView>
<-this is where you put your image->
</FrameLayout>
这是一个示例
最后放在堆栈上的项目将绘制在其下方项目的顶部。
这种布局使得在其他布局之上绘制非常容易,
特别是对于按钮放置等任务
要在框架布局中排列子项,请使用
android:layou-gravity
属性以及任何android:padding
还有你需要的安卓:margin
更改Framelayout中图像的顺序。您可以将图像作为最后一个放置在FrameLayout中。首先放置图像和其他项目。xml不正确。在这个序列中,子3在堆栈中位于第一位(在所有人之下),子2在堆栈中位于第二位(在子3之上),最后子1在堆栈中位于最后一位(在所有其他项之上),好的,先生。名字可能会改变。一旦他得到他想要的布局,我在这里真的很重要。谢谢你的建议。我只提到了这一点,因为xml描述了如何放置孩子,这与代码(你给他们的ID)不匹配。只是为了更好地理解,这就是我的答案。这是不对的,因为最后一个孩子总是放在上面,但是你提到“你的背景图像的宽度和高度要与父母匹配”
<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 >