FrameLayout
là đơn giản nhất ViewGroup
và ngăn xếp Views
theo thứ tự chúng được xác định trong XML bố cục; cái đầu tiên sẽ thấp hơn, và cái cuối cùng sẽ ở trên đầu.
Dưới đây là một ví dụ nơi View
s được bù đắp để minh họa rõ hơn về điểm:
Đây là XML bố trí với hai chồng chéo TextView
hộp. Độ lệch của hai hộp được thực hiện bằng cách sử dụng android:layout_gravity
trong khi android:gravity
là để căn giữa chính văn bản trong mỗi hộp.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="100dp">
<TextView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="top|left"
android:background="@android:color/holo_blue_light"
android:gravity="center"
android:text="First is below"/>
<TextView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="bottom|right"
android:background="@android:color/holo_green_light"
android:gravity="center"
android:text=" Last is on top"/>
</FrameLayout>
Nguồn
2016-09-15 18:54:16
RelativeLayout sẽ hoạt động nhưng bạn có thể sử dụng FrameLayout. – bhups