【发布时间】:2015-07-28 20:31:17
【问题描述】:
我的名字是库珀。对Java相当陌生(一个月左右)
如果你在哪里看 instagram,他们的图像堆叠在图像上,带有 cmets 等。
看起来 XML 布局只是被复制并粘贴在彼此之上。
这就是他们正在做的事情吗? 我该怎么做?
【问题讨论】:
我的名字是库珀。对Java相当陌生(一个月左右)
如果你在哪里看 instagram,他们的图像堆叠在图像上,带有 cmets 等。
看起来 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>
它是什么样子的:
【讨论】: