我刚开始学习android编程,从文档中了解到,RelativeLayout主要用于需要根据某些规则放置视图的情况,而FrameLayout则适用于需要重叠视图的情况。
但是不幸的是,在下面的程序中,我使用RelativeLayout来完成了FrameLayout的工作。虽然我的代码可以工作,但为了更好地理解,我是否忽略了一些区别呢? 此外,按钮是如何出现在我的图片上的?(即使其他图片也重叠了。)
但是不幸的是,在下面的程序中,我使用RelativeLayout来完成了FrameLayout的工作。虽然我的代码可以工作,但为了更好地理解,我是否忽略了一些区别呢? 此外,按钮是如何出现在我的图片上的?(即使其他图片也重叠了。)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ic_launcher"
/>
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:layout_alignParentTop="true"
android:layout_alignLeft="@id/imageView1"
/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1.0" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:text="Login" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:text="Register" />
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:text="Try application" />
</LinearLayout>
</RelativeLayout>