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 //自适应,根据内容 如果指定 ...
随机推荐
- CentOS6下编译安装Python2.7.6方法
关于在CentOS6下编译安装Python2.7.6的方法非常的多了,小编以前也介绍过相关的文章了,下面一聚教程小编再来为各位介绍一下吧,希望文章能帮助到各位. CentOS下面Python在升级 ...
- “弹出DVD驱动器错误”解决方法
错误描述:(win7环境) 买了个开发板,赠送了一些光盘,放在电脑光驱中打开后,电脑就疯狂响,可能是光盘质量太差.用完后在弹出时显示“弹出DVD驱动器错误”[见图1].直接按主机上弹出按钮也没有反应. ...
- C51单片机模拟I2C总线驱动程序设计
/********************************** I2C总线驱动 ******************************** 模块名:I2C总线驱动 型号:I2C 功能描述 ...
- 新发现一个函数:GradientFill
位于Msimg32.dll之中 https://msdn.microsoft.com/en-us/library/windows/desktop/dd144957(v=vs.85).aspx
- Java Socket 简单梳理
Sockets let you send raw streams of bytes back and forth between two computers, giving you fairly lo ...
- java设计模式--创建模式--原型模式
原型模式: 原型模式 概述 用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 适用性 .当一个系统应该独立于它的产品创建.构成和表示时. .当要实例化的类是在运行时刻指定时,例如,通过 ...
- poj 1088 动态规划+dfs(记忆化搜索)
滑雪 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Description Mi ...
- Python IDE的选择和安装
安装好Python后我们需要选择合适自己的IDE进行学习,虽然利用python默认的编辑器,或者直接文档编辑也可以进行基础的学习,但总归不是太方便,能够开发python项目的IDE很多,如sublim ...
- linux 之 tar 命令
通过SSH访问服务器,难免会要用到压缩,解压缩,打包,解包等,这时候tar命令就是是必不可少的一个功能强大的工具.linux中最流行的tar是麻雀虽小,五脏俱全,功能强大. tar 命令可以为linu ...
- Dice Notation(模拟)
Dice Notation Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit ...