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 控件属性的更多相关文章

  1. Android控件属性大全(转)

    http://blog.csdn.net/pku_android/article/details/7365685 LinearLayout         线性布局        子元素任意: Tab ...

  2. Android控件属性大全[整理转载]

    控件属性: android属性 Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料, 第一类:属性值为true或falseandroid:layout_ ...

  3. 【转载】Android控件属性大全

    控件属性: android属性 Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料, 第一类:属性值为true或falseandroid:layout_ ...

  4. 转:Android控件属性

    Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料,花费本人一个下午搞出来的,希望对其他人有用. 第一类:属性值为true或false android: ...

  5. Android控件属性android:visibility的invisible与gone的区别

    "invisible" : 不可见 "gone"      : 隐   藏 主要区别在于控件设置了invisible后控件不可见,但是保留了控件在界面上的空间, ...

  6. Android - 控件android:ems属性

    Android - 控件android:ems属性http://blog.csdn.net/caroline_wendy/article/details/41684255?utm_source=tui ...

  7. android控件的属性

    android控件的属性 本节描述android空间的位置,内容等相关属性及属性的含义 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 ( ...

  8. 关于Android控件EditText的属性InputType的一些经验,java组合多个参数

    关于Android控件EditText的属性InputType的一些经验 2013-11-14 15:08:02|  分类: 默认分类|举报|字号 订阅       1.InputType属性在代码中 ...

  9. Android控件常见属性

    1.宽/高android:layout_width android:layout_height// 取值match_parent //匹配父控件wrap_content //自适应,根据内容 如果指定 ...

随机推荐

  1. 电子工程师名片——UFI Command,USB盘符的显示

    USB Mass Storage类规范概述        USB Mass storage Device协议即海量存储设备协议适用于硬盘,U盘等大容量存储设备.协议使用的接口端点有BulkIn.Bul ...

  2. MFC与Qt的内存管理

    最近在做MFC向Qt的移植,在内存管理方面遇到了很头疼的问题,虽然不知道问题到底出在哪,先了解下这两个库的内存管理方式.于是转载两篇关于内存管理的文章. 一. Qt内存管理: 在Qt的程序中经常会看到 ...

  3. QT字体的设置

    摘要: QT4.7.0在移植到开发板上的时候,中文支持是必不可少的,如何让QT支持中文,如何制作QT支持的字体文件,如何使QT UI编辑器中的字号与开发板中的字号一致.作者通过实验进行了一一验证. 介 ...

  4. 关于VMWARE虚拟机安装GHOST版XP后不能硬盘启动问题

    工具: VMware Workstation 9.0 Ghost xp sp3 中英 双语版 现象:建立硬盘分区,设置活动分区...ghost安装顺利,安装完成后不能硬盘启动,如果从硬盘启动则黑屏,出 ...

  5. 经过一年时间的沉淀 再次回首 TCP Socket服务器编程--转

    ------------------ 前言 ------------------ 开发了这么多年,发现最困难的程序开发就是通讯系统. 其他大部分系统,例如CRM/CMS/权限框架/MIS之类的,无论怎 ...

  6. 一、crond简介

    crond 是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务 工具,并且会自动启动crond进程,cro ...

  7. JSP中的include的两种用法

    1.两种用法 <%@ include file=” ”%> <jsp:include page=” ” flush=”true”/> 2.用法区别 (1)执行时间上区别 < ...

  8. 为啥NSString的属性要用copy而不用retain

    之前学习生活中,知道NSString的属性要用copy而不用retain,可是不知道为啥,这两天我研究了一下,然后最终明确了. 详细原因是由于用copy比用retain安全,当是NSString的时候 ...

  9. Spring源代码由浅入深系列五 GetBean

    获取bean的过程如上图所看到的.下一章将继续图示解说createBean的过程. blog宗旨:用图说话 附:文件夹 Spring源代码由浅入深系列四 创建BeanFactory Spring源代码 ...

  10. hibernate某些版本(4.3)下报错 NoSuchMethodError: javax.persistence.Table.indexes()

    其实本来没啥大问题,但到网上查的时候发现了一些误人子弟的说法,所以还是记下来吧. 现象: hibernate从低版本升级到某一个版本时(我们是升到4.3.10)时,在程序启动时会报错: java.la ...