且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

框架和相对布局之间的区别?

更新时间:2023-12-04 11:09:28

在RelativeLayout的可以使用:

 的android:layout_toLeftOf =@ ID / some_view
机器人:layout_toRightOf =@ ID / some_view
机器人:layout_above =@ ID / some_view
机器人:layout_below =@ ID / some_view

要正确确保意见的阵容相对于对方。的FrameLayout,除了它只是利用重力将显示它的意见(没有关系)非常相似。

I'm new to android programming but from how much I have understood of the layouts from the documentation, RelativeLayout is mostly used when you need the views based on some rules and the FrameLayout when you want to overlap views.

But unfortunately for the following program I get the work of FrameLayout done by using RelativeLayout. I got my work done but for understanding, Am I missing something in the difference? Also, how did the buttons come over my image? (Even the other image is overlapping.)

<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>

The RelativeLayout can use :

android:layout_toLeftOf="@id/some_view"
android:layout_toRightOf="@id/some_view"
android:layout_above="@id/some_view"
android:layout_below="@id/some_view"

to make sure views lineup correctly in relation to each other. FrameLayout is very similar except it's only using gravity to put display it's views (with no relation).