【发布时间】:2012-07-21 17:28:12
【问题描述】:
我是 android 编程新手,但从我对 documentation 的布局的了解来看,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>
【问题讨论】:
标签: android android-layout android-relativelayout android-framelayout