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;
}
}
这样完成后的效果是这样的
可以看到button在文字的右边
分享到:
相关推荐
asp.net Jmail组件使用小记
git使用小记----作者:谭耀武概述本文以PublicCMS为例对git的一些操作进行说明fork版地址:https://gitee.com/tywo45/P
rman使用小记,一些必得过程,希望大家喜欢。
Display_Tag,一个很不错的开源列表组件,下面是我整理的使用小记。
阿里大数据分析平台使用小记,用于天池大数据竞赛平台,一些使用经验,不是完整的开发使用教程,仅供参考。具体的使用细节还得参考官网说明。
NULL 博文链接:https://zfwdl2005.iteye.com/blog/1308748
git使用小记----作者:谭耀武概述本文以FrameworkBenchmarks为例对git的一些操作进行说明fork版地址:https://github.c
android应用登录模块访问mysql数据库小记.pdf
vuex使用方法,小记总结
Sublime Text3 安装到使用个人小记
一些常用的技术总结,包括java基础,android 基础知识。
在Solaris上使用优盘小记-Solaris -华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,为7万用户提供服务
关于Jmail的使用介绍网上已经不少,我把自己的体验纪录一下,既帮助跟我一样的初学者也是个积累。 Jmail的使用主要有以下几点: 一. 安装:要在机器上安装Jmail组件,其实就是一个“Jmail.dll”,一般会被安装到C:...
在bootstrap项目中使用fontawesome-iconpicker插件选择图标的简单调用方法
【咬人草小记,阅读附答案】 咬人草小记阅读答案.docx
NULL 博文链接:https://goowolf.iteye.com/blog/520959
流程图与控制流图课堂小记.流程图与控制流图课堂小记.流程图与控制流图课堂小记.流程图与控制流图课堂小记.流程图与控制流图课堂小记.流程图与控制流图课堂小记.流程图与控制流图课堂小记.流程图与控制流图课堂小记....