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. dojo Tree 添加、删除节点

    var tree=this.tree; var store=tree.model.store; if(this.node){ console.log(this.node) var children=t ...

  2. Anniversary party(POJ 2342 树形DP)

    Anniversary party Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5767   Accepted: 3335 ...

  3. iOS开发多线程-线程间通讯

    一.NSThread 线程间的通讯 - (void)demoAboutNSThread { NSLog(@"demoAboutNSThread %@", [NSThread cur ...

  4. 关于STM32工程的错误,狗血错误。。。..\CMSIS\core_cm3.h(1087): error: #20: identifier "IRQn_Type" is undefined

    这件事还是要写一篇博客了,为了后来的人不换致命性的错误 辛辛苦苦写的一个四个不同的引脚不同时钟不同寄存器分别产生四种不同占空比不同周期的信号方波程序超级经典  PS:页尾上传PWM波形产生工程附件供大 ...

  5. poj 3318 Matrix Multiplication

    http://poj.org/problem?id=3318 矩阵A*矩阵B是否等于矩阵C #include <cstdio> #include <cstring> #incl ...

  6. NOI十连测 第四测 T2

    思路:线段树套可持久化treap,可持久化treap我还是第一次听说.. 改题的时候没看数据范围..乱开数组T_T #include<algorithm> #include<cstd ...

  7. Zookeeper 5、Zookeeper应用场景

    应用场景1 .统一命名服务 » 分布式应用中,通常需要有一套完整的命名规则,既能够产生唯一的名称又便于人识别和记住,通常情况 下用树形的名称结构是一个理想的选择,树形的名称结构是一个有层次的目录结构, ...

  8. 很少人知道的office专用卸载工具

    Microsoft Office是微软公司开发的一套基于 Windows 操作系统的办公软件套装.常用组件有 Word.Excel.Powerpoint等.当我们不需要再用了或者想安装旧版本的话,首先 ...

  9. svo的一些博客解析

    记录一边学习 白巧克力: svo代码笔记 http://blog.csdn.net/heyijia0327/article/details/51083398 卢彦斌:svo原理解析 东北大学孙志明:s ...

  10. iOS 无效的版本,提交成功,不出现版本号

    最近更新到 iOS 10,提交审核 会卡在 转菊花 ...需要更新到Xcode 8 去提交. 然后提交成功后,版本管理 新版本,构建版本 迟迟不出来.恭喜你,你的版本是无效的.请看看 你的 公司app ...