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. python笔记之ZipFile模块

    python笔记之ZipFile模块 zipfile模块用来做zip格式编码的压缩和解压缩的,zipfile里有两个非常重要的class, 分别是ZipFile和ZipInfo, 在绝大多数的情况下, ...

  2. django框架介绍

    主要内容 1.        Django框架发展 2.        Django架构,MTV模式 3.        开发流程 4.        开发实例——Poll python下各种框架 一 ...

  3. 身份证校验程序(下)- 零基础入门学习Delphi49

    身份证校验程序 让编程改变世界 Change the world by program [caption id="attachment_2699" align="alig ...

  4. jQuery.data的是jQuery的数据缓存系统

    jQuery.Data源码 jQuery.data的是jQuery的数据缓存系统 jQuery.data的是jQuery的数据缓存系统.它的主要作用就是为普通对象或者DOM元素添加数据. 1 内部存储 ...

  5. MongoDB insert performance rapidly dropping

    http://dba.stackexchange.com/questions/65554/mongodb-insert-performance-rapidly-dropping http://www. ...

  6. ./configure : /bin/sh^M : bad interpreter

    用命令行来编译Qt的时候发生标题尚的错误. 原因是文件中带有DOS行结束符,必须把它转换成UNix结束符 references: http://stackoverflow.com/questions/ ...

  7. 如何检索Android设备的唯一ID

    关于本文档 Android的开发者在一些特定情况下都需要知道手机中的唯一设备ID.例如,跟踪应用程序的安装,生成用于复制保护的DRM时需要使用设备的唯一ID.在本文档结尾处提供了作为参考的示例代码片段 ...

  8. 安装 Kali Linux 后需要做的 20 件事

    安装 Kali Linux 后需要做的 20 件事 本文含有我觉得有用的每一件事情.本文分为三大部分: 专门针对Kali用户 Kali Linux是来自Debian的一个特殊版本,Kali Linux ...

  9. < IOS > 文件中 某个类设置ARC,或者非ARC

    用-fno-objc-arc标记来禁用在ARC工程那些不支持ARC的文件的ARC用-fobjc-arc标记启用非ARC工程中支持ARC的文件 项目targets -> build phases ...

  10. bzoj3407 [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题

    Description     贝茜像她的诸多姊妹一样,因为从约翰的草地吃了太多美味的草而长出了太多的赘肉.所以约翰将她置于一个及其严格的节食计划之中.她每天不能吃多过H(5≤日≤45000)公斤的干 ...