android 的相对布局的使用小记
16lz
2021-01-23
android的布局方式有几个,线性布局,绝对布局,表格布局,相对布局,针布局(可以做动画效果 一针就是一个元素,每秒x针就是说屏幕上的元素一秒变化的数量)常用的是相对布局;RelativeLayout;
下面就简单使用一下相对布局,同时来复习android的工程的各个文件的作用;
在建好的一个工程中,打开main.xml文件
string.xml
R.java
这样完成后的效果是这样的
可以看到button在文字的右边
下面就简单使用一下相对布局,同时来复习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; }}
这样完成后的效果是这样的
可以看到button在文字的右边
更多相关文章
- Android矢量图(二)--VectorDrawable所有属性全解析
- 深入解析_Android的自定义布局
- Android通用圆角布局(兼容Android P)
- Android 中使用代码动态网格布局
- Android清单文件详解(六) ---- 节点的属性
- android Kotlin 继承、派生、接口、构造方式,方法、属性重写
- Android 横向布局中间填满
- Android性能优化之布局优化