Android 控件(button)对齐方法实现详解

2016-02-19 09:26 0 1 收藏

给自己一点时间接受自己,爱自己,趁着下午茶的时间来学习图老师推荐的Android 控件(button)对齐方法实现详解,过去的都会过去,迎接崭新的开始,释放更美好的自己。

【 tulaoshi.com - 编程语言 】

1,android:orientation
布局方向。horizontal是让所有的子元素按水平方向从左到右排列, vertical是让所有的子元素按竖直方向从上到下排列。

2,android:gravity 与 android:layout_gravity的区别android:gravity是指定本元素的子元素相对它的对齐方式。

android:layout_gravity是指定本元素相对它的父元素的对齐方式。
例如:
下面这里的linearlayout的android:gravity设为right,有两个子元素Button01和Button02。
java代码:
代码如下:

?xml version=”1.0″ encoding=”utf-8″?
LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:gravity=”right”

Button android:text=”button01″ android:id=”@+id/Button01″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”/Button
Button android:text=”button02″ android:id=”@+id/Button02″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”/Button
/LinearLayout

这个main.xml里的LinearLayout也是有两个子元素Button01和Button02。Button01的android:layout_gravity设为”left”,Button02的 android:layout_gravity设为”right”
java代码:
代码如下:

?xml version=”1.0″ encoding=”utf-8″?
LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”

Button
android:layout_gravity=”left”
android:text=”button01″
android:id=”@+id/Button01″
android:layout_width=”wrap_content” a
ndroid:layout_height=”wrap_content”/Button
Button
android:layout_gravity=”right”
android:text=”button02″
android:id=”@+id/Button02″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
/Button
/LinearLayout

FameLayout布局
FrameLayout是最简单的一个布局对象。它被定制为你屏幕上的一个空白备用区域,之后你可以在其中填充一个单一对象—比如,一张你要发布的图片。所有的子元素将会固定在屏幕的左上角;你不能为FrameLayout中的一个子元素指定一个位置。后一个子元素将会直接在前一个子元素之上进行覆盖填充,把它们部份或全部挡住(除非后 一个子元素是透明的)。

xml属性
1,用xml文件来定义界面,然后Activity的setContentView方法根据xml文件里的定义来创建真正的控件对象。好比说xml文件是设计图纸,setContentView是生产机器,它依照图纸生产出各种各样的杯具和洗具。
2,FrameLayout的xml属性来自三个地方:继承下来的,嵌套类定义的,自身类定义的。
3,具的属性可查阅官方文档。下面是刚才遇到的几个属性。
java代码:
代码如下:

android:id
//这个xml属性是继承自android.view类的xml属性。它为framelayout提供一个唯一识别符号,之后,程序要用到它时可以用View.findViewById() 或Activity.findViewById()来找到它。
android:layout_width: 布局宽
android:layout_height: 布局高
//它们的取值是fill_parent或wrap_content。
fill_parent :在x轴或则y轴上充满父容器的空间。
wrap_content :framelayout里的元素有多少宽高就多少宽高,
//这两个属性都是定义在android.widget.FrameLayout的嵌套类android.widget.FrameLayout.LayoutParams里。
android:background:背景
android:foreground :前景

来源:https://www.tulaoshi.com/n/20160219/1590798.html

延伸阅读
我们知道Intent的应用,可以启动别一个Activity,那么是否可以启动别外的一个应用程序呢,答案是可以的。 1、首先我们新建一个Android应用,名为AnotherPro,此应用什么内容都没有,用于被另外一个程序打开。 2、新建一个工程用于打开上面的应用,程序界面如下 3、修改程序代码,在onCreate中添加如下代码 anotherPro = (Button) fin...
代码如下:  public void payment() {   SQLiteDatabase db = dbOpenHelper.getReadableDatabase();   db.beginTransaction();//开始事务   try {    db.execSQL("update person set amount=amount-10 where personid=2");    db.execSQL("update person set amount=amount+...
一、在drawable下面添加xml文件rounded_editview.xml 代码如下: ?xml version="1.0" encoding="utf-8"? shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle"     solid android:color="#FFFFFF"/solid     padding android:left="10dp"  ...
首先先建布局文件,界面很简单,就是一个搜索框和下面的联系人列表:   代码如下: ?xml version="1.0" encoding="utf-8"? LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFD3D7DF" android:orientati...
闲来无事,琢磨琢磨Android中的手势交互,发现网上在手势方面的文章并不是很多,而且很多的参考价值并不大。于是出此博文,与大家共勉。鉴于我写此博文时对手势交互的研究也不是特深,如果有不正确的地方,还请各位博友批评指正。 首先,在Android系统中,每一次手势交互都会依照以下顺序执行。 1. 接触接触屏一刹那,触发一个MotionEvent...

经验教程

914

收藏

60
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部