Android 控件属性
TextView 文字属性
//文字左右居中
android:layout_centerHorizontal="true"
//文字垂直居中
android:layout_centerVertical="true"
//文字大小
android:textSize="80px"
//背景颜色
android:background="#00FF00"
//获取页面对象的值用findViewById 来获取
例子:获取TextView的值
TextView textView = (TextView)findViewById(R.id.空间ID);
----------------------------------------------------
2、View是所以控件的父类。
文本、按钮、多选、单选、布局、等等都集成View。
----------------------------------------------------
3、监听器的使用基本流程。
①获取代表控件的对象
②定义一个类,实现监听器接口
③生成监听器对象
④为控件绑定监听器对象
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout); textview = (TextView)findViewById(R.id.txtView);
textview.setText("第一个TextView");
textview.setBackgroundColor(Color.GREEN);
//拿到Button控件
btn = (Button)findViewById(R.id.btn);
ButtonListener btns = new ButtonListener();
btn.setOnClickListener(btns); } //监听器类
class ButtonListener implements OnClickListener
{
@Override
public void onClick(View view) {
count_S++;
textview.setText(count_S+"");
}
}
-----------------------------------------------------
4、布局方法分类(-)
1、linerLayout 线性布局
2、RelativeLayout 相对布局 用的比较多
3、ListView布局
4、GridView布局
-------------------------------------------
5、距离单位
1、距离单位px
2、距离单位dp
3、距离单位sp
4、控件的外边距和内边距
(1)什么是dpi (dots per inch)dpi是屏幕的细腻程度。
计算公式:
dpi = (height² + width²)开根号 ,除以 size
dp = dip(Device Independent pixels)
换算公式 px = dp *(dpi /160)
在dpi为160的屏幕上:1dp =1px
(2)sp 通常用于指定字体大小
① sp: scaled pixels
② sp单位通常用于指定字体大小
③ 当用户修改手机字体是,sp会随之改变
(3) 字体用sp,控件大小用dp。
-----------------------------------------------------------------------------
6、内边距和外边距
(1)设置内边距和外边距
7、CheckBox 全选和全不选
private CheckBox eatBox;
private CheckBox sleepBox;
private CheckBox dotaBox;
private CheckBox AllCheck;
private CheckBox CkLOL; private TextView textview;
private Button btn;
int count_S = ; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checkbox); eatBox = (CheckBox) findViewById(R.id.eatId);
sleepBox = (CheckBox) findViewById(R.id.sleepId);
dotaBox = (CheckBox) findViewById(R.id.dotaId);
AllCheck = (CheckBox)findViewById(R.id.AllCheckId);
CkLOL = (CheckBox)findViewById(R.id.LOL); AllCheckListener al = new AllCheckListener();
AllCheck.setOnCheckedChangeListener(al); } class AllCheckListener implements CompoundButton.OnCheckedChangeListener
{
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
//方法一:
if (isChecked)
{
eatBox.setChecked(true);
sleepBox.setChecked(true);
dotaBox.setChecked(true);
CkLOL.setChecked(true);
System.out.println("All Check");
}else{
eatBox.setChecked(false);
sleepBox.setChecked(false);
dotaBox.setChecked(false);
CkLOL.setChecked(false);
System.out.println("unCheck");
} ----------
方法二:
eatBox.setChecked(isChecked);
sleepBox.setChecked(isChecked);
dotaBox.setChecked(isChecked);
CkLOL.setChecked(isChecked);
}
8、单选按钮Radio
private RadioGroup radioGroup;
private RadioButton nan;
private RadioButton nv; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.radiobox); radioGroup = (RadioGroup) findViewById(R.id.radioGroupId);
nan = (RadioButton)findViewById(R.id.nanID);
nan.setChecked(true); //默认是第一个被选中 nv = (RadioButton)findViewById(R.id.nvId); RadioGroupListener listener = new RadioGroupListener();
radioGroup.setOnCheckedChangeListener(listener); } class RadioGroupListener implements RadioGroup.OnCheckedChangeListener
{
//id被选中单选单选按钮ID
@Override
public void onCheckedChanged(RadioGroup radioGroup, int id)
{
//radioGroup 有多个组情况要先判断是哪个Group
if (radioGroup.getId() == R.id.radioGroupId)
{
if (id == nan.getId())
{
System.out.println("选中男");
}else if (id==nv.getId())
{
System.out.println("选中nv");
}
}else{
System.out.println("没有选中按钮");
}
}
}
9、图片控件 ImageView
<ImageView
android:layout_width="match_parent"
android:layout_height="206dp"
android:id="@+id/imageView"
android:layout_gravity="center_vertical"
android:src="@mipmap/a12" /> // 图片路径
ScaleType 拉伸类型
10、android:layout_weight="1"
是平分剩余的空间,而不是把父容器平分
如果想让第一个控件占屏幕的1/3,第二个控件占2/3
<TextView
android:id="@+id/firstID"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#00FF00"
android:layout_weight=""
android:text="first101010"/> <TextView
android:id="@+id/secondID"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=""
android:background="#002200"
android:text="second"/> height 也是可以这样用。
11、相对布局
<TextView
android:id="@+id/firstView" //@+id 是创建ID
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="Hello World!"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/firstView" //@id 是引用ID 是存在的ID
android:background="#00FF00"
android:text="World Hello!"/>
Android 控件属性的更多相关文章
- Android控件属性大全(转)
http://blog.csdn.net/pku_android/article/details/7365685 LinearLayout 线性布局 子元素任意: Tab ...
- Android控件属性大全[整理转载]
控件属性: android属性 Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料, 第一类:属性值为true或falseandroid:layout_ ...
- 【转载】Android控件属性大全
控件属性: android属性 Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料, 第一类:属性值为true或falseandroid:layout_ ...
- 转:Android控件属性
Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料,花费本人一个下午搞出来的,希望对其他人有用. 第一类:属性值为true或false android: ...
- Android控件属性android:visibility的invisible与gone的区别
"invisible" : 不可见 "gone" : 隐 藏 主要区别在于控件设置了invisible后控件不可见,但是保留了控件在界面上的空间, ...
- Android - 控件android:ems属性
Android - 控件android:ems属性http://blog.csdn.net/caroline_wendy/article/details/41684255?utm_source=tui ...
- android控件的属性
android控件的属性 本节描述android空间的位置,内容等相关属性及属性的含义 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 ( ...
- 关于Android控件EditText的属性InputType的一些经验,java组合多个参数
关于Android控件EditText的属性InputType的一些经验 2013-11-14 15:08:02| 分类: 默认分类|举报|字号 订阅 1.InputType属性在代码中 ...
- Android控件常见属性
1.宽/高android:layout_width android:layout_height// 取值match_parent //匹配父控件wrap_content //自适应,根据内容 如果指定 ...
随机推荐
- django框架介绍
主要内容 1. Django框架发展 2. Django架构,MTV模式 3. 开发流程 4. 开发实例——Poll python下各种框架 一 ...
- python保留指定文件、删除目录其他文件的功能(2)
在(1)中脚本实现了保留指定文件的功能,但不能删除空目录,在此补上删除空目录的方法 def DeleteEmptyDir(path): for i in range(1,100): for paren ...
- MVC4商城项目四:应用Bundle捆绑压缩技术
从MVC4开始,我们就发现,项目中对Global.asax进行了优化,将原来在MVC3中使用的代码移到了[App_Start]文件夹下,而Global.asax只负责初始化.其中的BundleConf ...
- SQL Server 2008空间数据应用系列十一:提取MapInfo地图数据中的空间数据解决方案
原文:SQL Server 2008空间数据应用系列十一:提取MapInfo地图数据中的空间数据解决方案 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft SQL Serv ...
- Windows 7下可以使用的各个命令语句+C#打开
Windows 7下可以使用的各个命令语句: control.exe /name microsoft.folderoptions 启动资源管理器的 文件夹属性 选项卡 control.exe /n ...
- tomcat那些事
Tomcat7.0.22安装配置 1.下载tomcat7.0.22 下载地址:http://tomcat.apache.org/download-70.cgi 2.添加系统环境变量,我的电脑-> ...
- C++静态成员函数不能调用非静态成员变量
其实我们从直观上可以很好的理解静态成员函数不能调用非静态成员变量这句话因为无论是静态成员函数还是静态成员变量,它们 都是在类的范畴之类的,及在类的整个生存周期里始终只能存在一份.然而非静态成员变量和非 ...
- MongoDB基本命令随便敲敲
1,mongoDB状态,版本,当前连接的数据库名称
- hdu 5491 The Next(暴力枚举)
Problem Description Let L denote the number of 1s in integer D’s binary representation. Given two in ...
- Word Amalgamation
Problem Description In millions of newspapers across the United States there is a word game called J ...