[英]Android - Stack XML Layouts ontop of each other
我叫库珀。 对Java来说还很陌生(一个月左右)
如果您在哪里查看instagram,则它们的图像会堆叠在图像上,并带有注释等。
看起来XML布局只是被复制并粘贴在彼此之上。
那是他们在做什么吗? 我怎样才能做到这一点?
FrameLayout和RelativeLayout使您可以将视图彼此叠放,z索引按它们在代码中添加或在xml中编写的顺序排列。 布局基本上是ViewGroup的规则扩展,如果要在布局中包括其他布局,请查看<include>
和<merge>
标签: http : //developer.android.com/training/improving-layouts/reusing- layouts.html
这是一个使用FrameLayout
和一些TextViews
的示例。 此FrameLayout
所有视图将显示在(0,0)坐标处,但在子视图的单个视图的android:layout_marginLeft/android:layout_marginStart
和android:layout_marginTop
属性的尺寸中具有偏移量
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="11111111"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginTop="6dp"
android:layout_marginStart="6dp" />
<TextView
android:text="2222222"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="12dp"
android:layout_marginStart="12dp" />
<TextView
android:text="3333333"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginTop="18dp"
android:layout_marginStart="18dp" />
</FrameLayout>
看起来像什么:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.