当前位置: 首页 > 编程日记 > 正文

android 布局之RelativeLayout(相对布局)

android 布局分为LinearLayout TableLayout RelativeLayout FreamLayout AbsoluteLayout.

常用的有LinearLayout,TableLayout,RelativeLayout ,这几个布局不会应该手机屏幕大小而有变化。通常我们使用HVGA 大小的屏幕(320*480).

接下来我们学习RelativeLayout.

原文引入找不到了。这里记录一下。

看一下效果图吧。


还有两个常用组件的图片。



main.xml代码如果

<?xml version="1.0" encoding="utf-8"?>  
<!-- 相对布局  一个控件相对于另一个控件或者容器的位置。 -->  
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:orientation="vertical"  android:layout_width="fill_parent"  android:layout_height="fill_parent"  >  <TextView    android:id="@+id/describe_view"   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:text="@string/hello"  android:textColor="#556055"  />  <!-- 这个TextView相对于上一个TextView 在 它的下方所以设置属性为layout_below-->  <TextView  android:id="@+id/username_view"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_marginTop="12dp"  android:text="@string/username"  android:textColor="#556055"  android:layout_below="@id/describe_view"  />  <EditText  android:id="@+id/username_edit"  android:layout_width="90dp"  android:layout_height="40dp"  android:layout_marginTop="4dp"  android:layout_toRightOf="@id/username_view"  android:layout_below="@id/describe_view"  />  <TextView  android:id="@+id/sex_view"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_marginTop="12dp"  android:text="@string/sex"  android:textColor="#556055"  android:layout_below="@id/describe_view"  android:layout_toRightOf="@id/username_edit"  />  <RadioGroup  android:id="@+id/sex_radiogroup"  android:orientation="horizontal"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_toRightOf="@id/sex_view"  android:layout_below="@id/describe_view"  >  <!--第一个RadioButton -->  <RadioButton  android:id="@+id/male_radiobutton"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="男" android:checked="true" />  <!--第二个RadioButton -->  <RadioButton  android:id="@+id/woman_radiobutton"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="女"  />  </RadioGroup>  <TextView  android:id="@+id/age_view"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:paddingTop="25dp"  android:text="@string/age"  android:textColor="#556055"  android:layout_below="@id/username_view"  />  <EditText  android:id="@+id/brithday_edit"  android:layout_width="90dp"  android:layout_height="40dp"  android:layout_marginTop="4dp"  android:hint="@string/selectdate"  android:textSize="13sp"  android:gravity="center"  android:editable="false"  android:layout_toRightOf="@id/age_view"  android:layout_below="@id/username_edit"  /><TextView  android:id="@+id/education_view"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:paddingTop="25dp"  android:text="@string/education"  android:textColor="#556055"  android:layout_below="@id/sex_view"  android:layout_toRightOf="@id/brithday_edit"  />  <!-- 下拉列表控件 -->  <Spinner  android:id="@+id/edu_spinner"  android:layout_width="108dp"  android:layout_height="38dp"android:prompt="@string/prompt"  android:entries="@array/entries"android:layout_below="@id/sex_radiogroup"  android:layout_toRightOf="@id/education_view"  />  <TextView  android:id="@+id/interest_view"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:paddingTop="25dp"  android:text="@string/interest"  android:textColor="#556055"  android:layout_below="@id/age_view"  />  <!-- 复选框控件 -->  <CheckBox  android:id="@+id/car_check"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="@string/car"  android:textColor="#566156"  android:layout_toRightOf="@id/interest_view"  android:layout_below="@id/brithday_edit"  />  <CheckBox  android:id="@+id/sing_check"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_marginLeft="11dp"  android:text="@string/sing"  android:textColor="#566156"  android:layout_toRightOf="@id/car_check"  android:layout_below="@id/brithday_edit"  />  <CheckBox  android:id="@+id/movie_check"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_marginLeft="11dp"  android:text="@string/movie"  android:textColor="#566156"  android:layout_toRightOf="@id/sing_check"  android:layout_below="@id/brithday_edit"  />  <Button android:layout_width="100dp"  android:layout_height="40dp"  android:text="@string/notify"android:id="@+id/notity"android:layout_marginLeft="20dp"  android:layout_marginTop="15dp"  android:layout_below="@+id/sing_check"/><Button  android:id="@+id/submit_button"  android:layout_width="100dp"  android:layout_height="40dp"  android:text="@string/submit"  android:gravity="center"  android:layout_below="@id/movie_check"  android:layout_marginLeft="210dp"  android:layout_marginTop="15dp"  />  </RelativeLayout> 

string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources><string name="hello">Hello World, LayoutDemoActivity!</string><string name="app_name">LayoutDemo</string><string name="username">用	户:</string><string name="sex">性别:</string><string name="selectdate">出生日期</string><string name="education">学历:</string><string name="interest">爱	好:</string><string name="age">年	龄:</string><string name="car">汽车</string><string name="sing">唱歌</string><string name="movie">电影</string><string name="submit">提交</string><string name="prompt">学历</string><string-array name="entries"><item>本科</item><item>专科</item><item>研究生</item><item>硕士</item><item>博士</item></string-array><string name="notify">通知</string><string name="content">Android是一种以Linux为基础的开放源码操作系统,主要使用于便携设备。目前尚未有统一中文名称,中国大陆地区较多人使用安卓(非官方)或安致(官方)。Android操作系统最初由Andy Rubin开发,最初主要支持手机。2005年由Google收购注资,并拉拢多家制造商组成开放手机联盟开发改良,逐渐扩展到到平板电脑及其他领域上。 2010年末数据显示,仅正式推出两年的操作系统的Android已经超越称霸十年的诺基亚Symbian系统,跃居全球最受欢迎的智能手机平台。Android的主要竞争对手是苹果的IOS,微软的WP7以及RIM的Blackberry OS。</string>
</resources>

又下主要代码的实现,有一个通知的代码。

package com.hkrt.action;import java.util.Calendar;import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.Toast;public class LayoutDemoActivity extends Activity {private  EditText brithdayEditText   = null;   EditText userName;RadioButton male;RadioButton woman;Spinner  sEducation;String sex=null;CheckBox car,sing,movie;//爱好StringBuffer hobby = new StringBuffer();@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);brithdayEditText =(EditText) this.findViewById(R.id.brithday_edit);brithdayEditText.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Calendar c = Calendar.getInstance();new DatePickerDialog(LayoutDemoActivity.this,new DatePickerDialog.OnDateSetListener(){@Overridepublic void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {brithdayEditText.setText(year+"-"+(monthOfYear+1)+"-"+dayOfMonth);}},c.get(Calendar.YEAR),c.get(Calendar.MONTH),c.get(Calendar.DAY_OF_MONTH)).show();}});userName =(EditText)this.findViewById(R.id.username_edit);male =(RadioButton)this.findViewById(R.id.male_radiobutton);woman =(RadioButton)this.findViewById(R.id.woman_radiobutton); sEducation =(Spinner)this.findViewById(R.id.edu_spinner);car = (CheckBox)this.findViewById(R.id.car_check);sing =(CheckBox) this.findViewById(R.id.sing_check);movie = (CheckBox)this.findViewById(R.id.movie_check);Button buttonSub = (Button)this.findViewById(R.id.submit_button);buttonSub.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if(userName.getText().toString().trim().length()==0){Toast toast =	Toast.makeText(getApplicationContext(), "用户名不能为空", 0);toast.setGravity(Gravity.CENTER, 0, 0);View toastView = toast.getView();ImageView image = new ImageView(LayoutDemoActivity.this);image.setImageResource(R.drawable.icon1);LinearLayout ll = new LinearLayout(LayoutDemoActivity.this);ll.addView(image);ll.addView(toastView);toast.setView(ll);toast.show();}else{if(male!=null){sex=male.getText().toString();}else{sex=woman.getText().toString();}if(car.isChecked()){hobby.append(car.getText()).append("|");}  if(sing.isChecked()){hobby.append(sing.getText()).append("|");}  if(movie.isChecked()){hobby.append(movie.getText());}Toast.makeText(getApplicationContext(), userName.getText() +""+ sex+""+ brithdayEditText.getText()+""+sEducation.getSelectedItem().toString()+""+hobby.toString(), 0).show();System.out.println("结果"+userName.getText() +""+ sex+""+ brithdayEditText.getText()+""+sEducation.getSelectedItem().toString()+""+hobby.toString());}}});/**通知的demo示例*/Button notityBut = (Button)this.findViewById(R.id.notity);notityBut.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent(LayoutDemoActivity.this,OtherActivity.class);PendingIntent contentIntent = PendingIntent.getActivity(LayoutDemoActivity.this, 0, intent, 0);Notification notify = new Notification();notify.icon=R.drawable.icon1;//notify.sound=Uri.parse("file:///sdcard/Crazy.mp3");notify.tickerText="启动otherActivity通知";notify.when=System.currentTimeMillis();notify.defaults=Notification.DEFAULT_SOUND;notify.defaults=Notification.DEFAULT_ALL;notify.setLatestEventInfo(LayoutDemoActivity.this, "普通通知", "点击查看", contentIntent);NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);manager.notify(0, notify);}});}
}

注:通知是打开另一个activity,


转载于:https://www.cnblogs.com/java20130726/archive/2011/11/08/3218338.html

相关文章:

【js】实现分页查询操作的步骤

1、将CSS的代码复制到goodList.jsp 2、引入common 代码实现&#xff1a; <% include file"../common/common.jsp"%> 3、引入jstl 代码实现&#xff1a; <% taglib prefix"c" uri"http://java.sun.com/jsp/jstl/core"%> 注意&…

Orchard:如何生成Hello World模块

在Orchard架构介绍中对Orchard的一些架构内容进行了介绍&#xff0c;下图是Orchard自带的一些模块&#xff0c; 本篇讲解一下如何扩展Orchard来生成我们的第一个模块。 介绍 Orchard构建在ASP.NET MVC之上&#xff0c;MVC是一个应用模式&#xff0c;我在信息系统开发平台OpenE…

通过域名访问自己部署到服务器上的项目

通过域名访问自己部署到服务器上的项目 如何不输入项目名端口号直接访问java web项目 1、省略输入端口号的步骤 在Linux的下面部署了tomcat&#xff0c;为了安全我们使用非root用户进行启动&#xff0c;但是在域名绑定时无法直接访问80端口号。众所周知&#xff0c;在unix下&am…

【java】异常的分类

注&#xff1a; 1、exception是人工可以修复的&#xff0c;但error的话很少出现&#xff0c;如果出现就无能为力了。 2、我们将所有派生于EXCEPTION和ERROR的类的所有异常称为&#xff08;unchecked&#xff09;非受查异常&#xff0c;其余为受查&#xff08;checked&#xf…

【免费软件测试视频-0013】——Loadrunner9.0 SLA Analysis

LR9.0---SLA Analysis http://www.3atesting.com/mv/bencandy.php?fid15&id16转载于:https://www.cnblogs.com/umain/archive/2008/09/28/1301310.html

训练听力的相关方法

一、听写熟悉一些固定发音 二、多阅读相关的文章&#xff0c;文章相关内容越熟悉&#xff0c;听力效果越好【重要】 三、首先没有听懂的一些音不会影响后面的理解 四、解决口音问题的唯一方法是&#xff0c;多阅读、记忆相关内容【签证及联系教授也要注意】转载于:https://www.…

PHP生成PDF文档的FPDF类

以前在PHP4的早期版本中用PDFlib生成PDF文档比较容易&#xff0c;现在升级到PHP5了&#xff0c;发现更麻烦了&#xff0c;装的PHP 5.2.4默认没有PHPlib&#xff0c;从php.net上找了一个&#xff0c;装上竟一直报错&#xff0c;开始以为是版本兼容问题&#xff0c;后来在租来的服…

Codeforces Round #466 (Div. 2)

http://codeforces.com/contest/940 A水题 //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tunenative") //#pragma …

WinCE中串口驱动及接口函数介绍(转载)

作者&#xff1a;ARM-WinCE 在WinCE中&#xff0c;串口驱动实际上就是一个流设备驱动,具体架构如图&#xff1a; 串口驱动本身分为MDD层和PDD层。MDD层对上层的Device Manager提供了标准的流设备驱动接口(COM_xxx)&#xff0c;PDD层实现了HWOBJ结构及结构中若干针对于串口硬件操…

【jsp】写jsp文件的准备

1、引入jstl 代码实现&#xff1a; <% taglib prefix"c" uri"http://java.sun.com/jsp/jstl/core" %> 2、编写common文件 代码实现&#xff1a; <c:set var"ctxpath" value"${pageContext.request.contextPath }">&l…

studio2008 无法显示该网页

莫名奇妙的studio调试的时候页面显示无法显示该网页&#xff0c;差网页后得知原来是C:\WINDOWS\system32\drivers\etc下的Hosts文件被修改了&#xff0c; 确认里面有127.0.0.1 localhost 行转载于:https://www.cnblogs.com/sunshinecc/archive/2011/11/11/2245596.html

侠客X官方网站成立,第一个内测版本即将放出,敬请期待.

这是一个难忘的日子&#xff0c;西方的情人节&#xff0c;本站的成立代表侠客X&#xff0c;即将与大家见面了。 我们的要做的是&#xff0c;传承侠客站群经典模式&#xff0c;打造SEO王者力作&#xff0c;侠客X即将公开测试&#xff0c;敬请期待。 http://xpk.in Qin 转载于:ht…

HSSFWorkbook 与 XSSFWorkbook

项目中一直使用NPOI与memcached,一直相安无事,但是最近升级了npoi到最新版本,发生了ICSharpCode.SharpZipLib的版本冲突问题. 因为此前一直使用的是NPOI的1.x的版本,用的SharpZipLib是0.84版本,而升级到最新版本以后,SharpZipLib的版本变成了0.86版本. 但是memcached的却没有最…

P1066 2^k进制数 NOIP 2006 提高组 第四题

洛谷蓝题&#xff08;点击跳转&#xff09; 提高组 第四题 题目描述 设r是个2^k 进制数&#xff0c;并满足以下条件&#xff1a; &#xff08;1&#xff09;r至少是个2位的2^k 进制数。 &#xff08;2&#xff09;作为2^k 进制数&#xff0c;除最后一位外&#xff0c;r的每一位…

线段树专辑——pku 2886 Who Gets the Most Candies?

http://poj.org/problem?id2886 恩&#xff0c;分糖果&#xff0c;快乐的童年啊&#xff01; 题目意思大概n个小孩围成一个圈&#xff0c;每个小孩手里有张卡片&#xff0c;记录着一个数字。开始从第k个孩子&#xff0c;该孩子离开圈子&#xff0c;然后告诉别人他手里的数字&a…

【jsp】通过get和post传值的区别

GET与POST的区别&#xff1a; GET方式提交表单&#xff0c;请求的参数在请求的头部&#xff0c;可以通过request.getQueryString()获取到请求参数及其参数值&#xff1b;POST方式提交表单&#xff0c;请求的参数在请求体中&#xff0c;所以request.getQueryString()方法无法获…

php获取输入流

uc中的用到的代码(在api/uc.php)代码&#xff1a; $post xml_unserialize(file_get_contents(php://input));&#xfeff; php手册&#xff08;http://cn.php.net/manual/zh/wrappers.php.php&#xff09;说明: php://input allows you to read raw data from the request bod…

微信小程序实例源码大全demo下载

怎么本地测试微信小程序实例源码 1.下载源码2.打开微信开发者工具3.添加项目->选择本项目目录->编译执行微信小程序实例源码大全 微信小程序游戏类demo&#xff1a;识色&#xff1b;从相似颜色中挑选不同的一个 源码链接&#xff1a;http://www.wxapp-union.com/forum.ph…

RabbitMQ 学习

参考&#xff1a;https://www.rabbitmq.com/getstarted.html 先在本地安装RabbitMQ 组件(需要安装Erlang组件&#xff09;&#xff0c;启动服务。 激活 RabbitMQs Management Plugin 使用RabbitMQ 管理插件&#xff0c;可以更好的可视化方式查看Rabbit MQ 服务器实例的状态。 打…

怎样提高WebService的性能

服务器端WebService程序using System.Runtime.Serialization.Formatters.Binary;using System.IO;using System.IO.Compression;using System.Data.SqlClient;………public class Service1 : System.Web.Services.WebService{[WebMethod(Description "直接返回 DataSet 对…

【jsp】jsp的内置对象(部分)

一、response 1、setStatus:设置响应状态码。 代码实现&#xff1a; response.setStatus(550); 更改的位置如图&#xff1a; 2、sendRedirect:服务器端跳转 代码实现&#xff1a; response.sendRedirect("Success.jsp"); 3、setContentRType:设置返回内容类型…

linux tar的使用方法

tar [-cxtzjvfpPN] 文件与目录 ....参数&#xff1a;-c &#xff1a;建立一个压缩文件的参数指令(create 的意思)&#xff1b;-x &#xff1a;解开一个压缩文件的参数指令&#xff01;-t &#xff1a;查看 tarfile 里面的文件&#xff01;特别注意&#xff0c;在参数的下达中&a…

关闭webstorm自动保存,并显示文件未保存标识

1.取消自动保存 2.显示编辑状态设置&#xff1a; 转载于:https://www.cnblogs.com/webSong/p/8807732.html

【转】SQL函数:字符串中提取数字,英文,中文,过滤重复字符

SQL函数&#xff1a;字符串中提取数字&#xff0c;英文&#xff0c;中文&#xff0c;过滤重复字符 --提取数字IF OBJECT_ID(DBO.GET_NUMBER) IS NOT NULLDROP FUNCTION DBO.GET_NUMBERGOCREATE FUNCTION DBO.GET_NUMBER(S VARCHAR(100))RETURNS VARCHAR(100)ASBEGINWHILE PATI…

【java】实现数据在页面之间传输

传数据页面&#xff1a; 方法&#xff1a;使用a标签传输数据 格式&#xff1a; <a name"C03S417" href"getRoomFinal.jsp?roomNumberC03S415">入住 </a> 接收数据页面&#xff1a; 方法&#xff1a; &#xff08;1&#xff09;使用java代…

Android画图学习总结(四)——Animation(上)

随着对Drewable的深入了解&#xff0c;发现了Drawable更加强大的功能&#xff1a;显示Animation。Android SDK介绍了2种Animation&#xff1a; Tween Animation&#xff1a;通过对场景里的对象不断做图像变换(平移、缩放、旋转)产生动画效果 Frame Animation&#xff1a;顺序播…

ES6 Rest参数

Rest参数接收函数的多余参数&#xff0c;组成一个数组&#xff0c;放在形参的最后&#xff0c;形式如下&#xff1a; function func(a, b, ...theArgs) { // ... }rest参数只包括那些没有给出名称的参数&#xff0c;注意&#xff0c;rest参数之后不能再有其它参数&#xff08;即…

Data - 深入浅出学统计 - 下篇

本文是已读书籍的内容摘要&#xff0c;少部分有轻微改动&#xff0c;但不影响原文表达。 &#xff1a;以漫画形式来讲解最基本的统计概念和方法。 ISBN: 9787121299636https://book.douban.com/subject/26906845/2 - 探寻参数 2.1 - 中心极限定理&#xff08;Central Limit The…

[网摘学习]在Ubuntu上安装和配置OpenStack Nova之二

再收藏一份Openstack的文章,这两天的操作与此相同.但其中出现的问题还需要查找原因.待个人继续学习研究. 原文参考:http://www.linuxde.net/2011/11/1599.html此处仅供学习记录,版权归原作者. OpenStack 是 Python 2.6 写的&#xff0c;CentOS 5.6 上默认的是 Python 2.4 的环境…

【Linux】Linux computer文件夹下各种文件的作用

1、bin&#xff1a;放可执行文件&#xff0c;一些Linux的命令 注&#xff1a;Linux的命令最终都是一些程序&#xff0c;这些程序都放在bin目录和sbin目录 2、boot : 启动目录 3、dev : 存放设备 注&#xff1a;在Linux中把所有硬件都叫设备 4、etc&#xff1a; 安装软件的各种…