android 的相对格局的使用小记

android 的相对布局的使用小记
android的布局方式有几个,线性布局,绝对布局,表格布局,相对布局,针布局(可以做动画效果 一针就是一个元素,每秒x针就是说屏幕上的元素一秒变化的数量)常用的是相对布局;RelativeLayout;
下面就简单使用一下相对布局,同时来复习android的工程的各个文件的作用;
在建好的一个工程中,打开main.xml文件
<?xml version="1.0" encoding="utf-8"?>
//这里修改成了RelativeLayout 是相对布局了;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
/*这是第一个元素,文字内容是android:text="@string/hello"引用的string.xml中的hello这个属性的值;布局高度和宽度都是随着内容来设定的。这里有个新的标签属性,
android:id这个属性是给这个标签起一个唯一的名字,起名字的方法是="@+id/customput
这个值的意思是在R.java文件中的id的静态变量中添加一个名字是customput的常量;当你写好这个属性和值保持后 你去看你的R.java文件 你会发现自动产生了
public static final class layout {
        public static final int main=0x7f030000;
    }
这些代码;这样你就知道怎么用了把
*/
<TextView  
    android:text="@string/hello"
    android:id="@+id/customput"
    android:layout_height="wrap_content" android:layout_width="wrap_content"/>
/*这是另一个元素,这个元素和上面的一样 是个文本框,他的位置是在上一个元素的右边 你问我怎么知道的?是这句话告诉我的android:layout_toRightOf="@id/customput"
他用了上个元素的唯一的名字*/
    <TextView  
    android:layout_toRightOf="@id/customput"
    android:text="@string/submitName"
    android:layout_height="wrap_content" android:layout_width="wrap_content"/>
</RelativeLayout>


string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, HelloWorldActivity!</string>
    <string name="app_name">第一个应用</string>
    <string name="submitName">button</string>
</resources>


R.java
/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.android.activity;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class id {
        public static final int customput=0x7f050000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
        public static final int submitName=0x7f040002;
    }
}


这样完成后的效果是这样的
android 的相对格局的使用小记
可以看到button在文字的右边