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

Aa捍卫正义

Aa捍卫正义

2016-02-19 09:26

给自己一点时间接受自己,爱自己,趁着下午茶的时间来学习图老师推荐的Android 控件(button)对齐方法实现详解,过去的都会过去,迎接崭新的开始,释放更美好的自己。
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 :前景
展开更多 50%)
分享

猜你喜欢

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

编程语言 网络编程
Android 控件(button)对齐方法实现详解

Android控件系列之Button以及Android监听器使用介绍

编程语言 网络编程
Android控件系列之Button以及Android监听器使用介绍

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

Android中button实现onclicklistener事件的两种方式

编程语言 网络编程
Android中button实现onclicklistener事件的两种方式

DIV实现垂直居中对齐的方法

Web开发
DIV实现垂直居中对齐的方法

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

android控件之WebView控件缩小

编程语言 网络编程
android控件之WebView控件缩小

基于Android开发支持表情的实现详解

编程语言 网络编程
基于Android开发支持表情的实现详解

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

sql 多条件组合查询并根据指定类别找出所有最小子类别的SQL语句备忘

sql 多条件组合查询并根据指定类别找出所有最小子类别的SQL语句备忘

玫瑰花旳哀伤 是因为它带刺 还是痛苦的呻吟 - QQ图案分组

玫瑰花旳哀伤 是因为它带刺 还是痛苦的呻吟 - QQ图案分组
下拉加载更多内容 ↓