Android基础,用户界面设计(布局)
2017-07-18 23:09
411 查看
学习内容
Android布局文件存放于res/layout目录下
在布局时注意点
1)确定布局管理器类型
2)在布局管理器中添加需要的组件
3)修改Activity里只想的布局文件
ATwstView文本视图
TextView是Android中用的最多的控件,显示一行或者多行文本,也可以给上下左右设置图片, 并且结合SpannableString和其子类可以做到文本混排。
1. java.lang.Object
|-android.view.View
|-android.widget.TextView
View常用属性
注意:所有试图类都直接或间接继承于View,共享View的所有属性和方法
TextView
TextView是Android中最基础也是最常用的一个控件。 它主要用于在界面上显示一段文本信息,比如新建工程时的HelloWord;
常用的属性
- android:autoLink 设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接。
//可选值(none/web/email/phone/map/all)
- android:drawableTop 在TextView上下左右输出一张图片
- android:drawableBottom
- android:drawableLeft
- android:drawableRight
- android:gravity 设置文本位置, 入设置成center,文本将居中显示。
- android:lines 设置文本的行数, 设置两行就显示两行, 即使第二行没有数据。
- android:text 设置显示文本内容
- android:textColor 设置文本颜色
- android:textSize设置文本大小
- android:gravity 来指定文字的对齐方式,可选值有(top,bottom,left,right, center等,可以用“|”来同时指定多个值)
padding设置对应
TextView设置跑马灯效果
设置单行,焦点, ellipsize。和宽度小于文本长度
Button按钮
Android中, button继承与TextView, 并且设置了样式,属性和方法与TextView一模一样。
ImageView图片
ImageView用来显示任何Drawable对象,通常用来显示图片
常用的属性
- Android:src 用来设置drawable文件夹下的图片或者选择器
- scaleType 图片的缩放方式,当图片大小和控件大小不一致时使用
计算机按键布局代码
Android布局文件存放于res/layout目录下
在布局时注意点
1)确定布局管理器类型
2)在布局管理器中添加需要的组件
3)修改Activity里只想的布局文件
ATwstView文本视图
TextView是Android中用的最多的控件,显示一行或者多行文本,也可以给上下左右设置图片, 并且结合SpannableString和其子类可以做到文本混排。
1. java.lang.Object
|-android.view.View
|-android.widget.TextView
View常用属性
注意:所有试图类都直接或间接继承于View,共享View的所有属性和方法
1. android:background 设置背景色/背景图片 2. android:clickable 是否相应点击事件 3. android:id 给当前View设置一个在当前布局中的唯一编号 4. android:onClick 点击是从上下文中调用指定的方法 5. android:padding 设置上下左右控件内部与控件的边距,以像素为单位填充空白。 6. android: visibility 设置是否显示View。 //可选值 //visible(默认,显示) //invisible(不显示,但是仍然占用空间) //gone(不显示,不占用空间)
TextView
TextView是Android中最基础也是最常用的一个控件。 它主要用于在界面上显示一段文本信息,比如新建工程时的HelloWord;
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/text_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World!" /> </LinearLayout>
常用的属性
- android:autoLink 设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接。
//可选值(none/web/email/phone/map/all)
- android:drawableTop 在TextView上下左右输出一张图片
- android:drawableBottom
- android:drawableLeft
- android:drawableRight
- android:gravity 设置文本位置, 入设置成center,文本将居中显示。
- android:lines 设置文本的行数, 设置两行就显示两行, 即使第二行没有数据。
- android:text 设置显示文本内容
- android:textColor 设置文本颜色
- android:textSize设置文本大小
- android:gravity 来指定文字的对齐方式,可选值有(top,bottom,left,right, center等,可以用“|”来同时指定多个值)
padding设置对应
TextView设置跑马灯效果
设置单行,焦点, ellipsize。和宽度小于文本长度
Button按钮
Android中, button继承与TextView, 并且设置了样式,属性和方法与TextView一模一样。
ImageView图片
ImageView用来显示任何Drawable对象,通常用来显示图片
常用的属性
- Android:src 用来设置drawable文件夹下的图片或者选择器
- scaleType 图片的缩放方式,当图片大小和控件大小不一致时使用
计算机按键布局代码
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="4" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" > <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="MC" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="MR" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="MS" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="M+" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="M-" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" > <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="←" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="CE" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="C" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="±" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="√" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" > <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="7" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="8" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="9" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="/" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="%" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" > <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="4" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="5" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="6" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="*" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="1/x" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="2" android:orientation="horizontal" > <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="1" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="2" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="0" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:orientation="horizontal" > <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical" > <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="3" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="." /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical" > <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="+" /> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="-" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical" > <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="=" /> </LinearLayout> </LinearLayout> </LinearLayout>
相关文章推荐
- Android用户界面设计:布局基础
- Android用户界面设计:布局基础
- Android用户界面设计:布局基础
- android布局基础及范例:QQ登陆界面设计
- Android界面设计基础:控件焦点4个步骤_12点圆形布局
- Android用户界面设计:线性布局
- Android用户界面设计:框架布局
- android布局基础及范例(一):QQ登陆界面设计
- Android——用户界面设计(布局)
- Android用户界面设计“.NET研究”:框架布局
- Android用户界面设计:线性布局
- Android用户界面设计:框架布局
- Android用户界面设计:相对布局
- Android用户界面设计:相对布局
- Android用户界面设计:线性布局
- Android用户界面设计:线性布局“.NET研究”
- Android用户界面设计——关于布局的学习笔记
- Android用户界面设计:框架布局(转)
- Android用户界面设计:线性布局
- 【Android开发】用户界面设计-使用XML布局文件控制UI界面