2

基本上,标题不言自明。我想把元素放在不同的元素之上。我可以使用绝对布局,但据说它已被弃用。

还有其他方法吗?如果不是,他们为什么要弃用 AbsoluteLayout?

4

2 回答 2

7

RelativeLayout 的默认行为会将所有元素堆叠在左上角,因此此布局:

<RelativeLayout
android:width="fill_parent"
android:height="fillparent">

<ImageView
android:width="wrap_content"
android:height="wrap_content"
android:src="@drawable/img1" />

<ImageView
android:width="wrap_content"
android:height="wrap_content"
android:src="@drawable/img2" />

</RelativeLayout>

将在屏幕左上角将两个图像堆叠在一起。相对布局提供了许多其他属性,允许您将视图移动到屏幕上的不同位置。但是这个想法是它可以更好地缩放到不同的大小,因为您不会硬编码 x,y 值来确定您想要元素去哪里。

于 2012-08-22T13:19:48.693 回答
0

我很确定您可以使用RelativeLayout 进行这种操作。

这是文档:http: //developer.android.com/reference/android/widget/RelativeLayout.html

于 2012-08-22T13:15:05.260 回答