框架和相对布局之间的区别? [英] Difference between Frame and Relative layout?

查看:222
本文介绍了框架和相对布局之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新到Android编程,但是从我有多少来自理解布局文档,RelativeLayout的,当你想重叠的看法时,您需要根据一些规则和的FrameLayout的意见大多使用。

但不幸的是下面的程序,我得到的FrameLayout通过使用RelativeLayout的所做的工作。我有我的工作完成,但对于理解,我缺少的区别的东西吗?
此外,你怎么按钮过来我的形象? (即使是其他的图像是重叠的。)

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>< ImageView的
    机器人:ID =@ + ID / imageView1
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@绘制/ ic_launcher
    />< ImageView的
    机器人:ID =@ + ID / imageView2
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=@绘制/ ic_launcher
    机器人:layout_alignParentTop =真
    机器人:layout_alignLeft =@ ID / imageView1
    /><的LinearLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignBottom =@ + ID / imageView1
    机器人:比重=中心
    机器人:方向=横向
    机器人:weightSum =1.0><按钮
    机器人:ID =@ + ID /按钮1
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_weight =0.33
    机器人:文字=登录/><按钮
    机器人:ID =@ + ID /按钮2
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_weight =0.33
    机器人:文字=注册/><按钮
    机器人:ID =@ + ID /按钮3
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_weight =0.33
    机器人:文字=尝试应用/>< / LinearLayout中>< / RelativeLayout的>


解决方案

在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).

这篇关于框架和相对布局之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆