1. 介绍

Android控件大多位于android.widget, android.view.View为他们的父类
对于Dialog系列, android.app.Dialog为父类

Android的原生控件, 一般是在res/layout下的xml文件中声明
然后在Activity通过使用super.setContentView(R.layout.layout_name)来加载layout
在Activity中获取控件的引用使用super.findViewById(R.id.widget_id), 然后接可以使用这个引用对控件进行操作(添加监听, 设置内容).

值得提出的是, 上一篇文章中的Layout(LinearLayout, TableLayout, RelativeLayout, …)都是控件.

2. 控件关系

View子类结构图:

TextView子类结构:

ViewGroup子类结构图:

FrameLayout子类结构:

android.app.Dialog子类结构:

3. 基本控件

3.1 文本类控件

常用文本类控件如下:

TextView                负责展示文本, 不可编辑
EditText 可编辑文本控件

3.2 按钮类控件

Button                   按钮
ImageButton 图片按钮
ToggleButton 开关按钮
RadioButton/RadioGroup 单选按钮
CheckBox 复选按钮

3.3 图片类控件

ImageView                负责显示图片

3.4 进度条控件

ProgressBar              显示进度条, 不可拖动
SeekBar 拖动条
RatingBar 星级评分条

3.5 时间类控件

TextClock                文本时钟
AnalogClock 模拟时钟
Chronometer 计时器
DatePicker 日期选择器
TimePicker 时间选择器
CalendarView 日期视图

3.6 提示&对话框控件

Toast                    消息提示框
Notification 状态栏通知
AlertDialog 对话框
ProgressDialog 进度条对话框

4. 布局类控件

4.1 基本布局类控件

详细信息参考<Activity布局>

4.2 适配器布局类控件

该类控件需要Adapter(BaseAdapter, ArrayAdapter, SimpleAdapter)来配合使用

ListView                 列表视图
ExpandableListView 可折叠的列表
GridView 网格视图
Spinner 列表选项框
ViewFlipper 翻转视图
Gallery 画廊视图

下面是关于ListView的简单使用方法

<!-- activity_main.xml -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.lineto.testlistview.MainActivity">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout> <!-- layout_item,xml -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingTop="2dp"
android:paddingRight="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/name"
android:width="180dp"
android:textSize="10pt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/ip"
android:textSize="10pt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
/* MainActivity.java */
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); ListView listView = (ListView)findViewById(R.id.listview);
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>(); String[] stringsName = {"Jerry", "Penny", "Jimmy"};
String[] stringsIp = {"192.169.0.1", "192.168.1.1", "192.168.2.1"};
for (int i = 0; i < stringsName.length; i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", stringsName[i]);
map.put("ip", stringsIp[i]);
list.add(map);
} SimpleAdapter simpleAdapter = new SimpleAdapter(this, list, R.layout.layout_item,
new String[]{"name", "ip"},
new int[]{R.id.name, R.id.ip}); listView.setAdapter(simpleAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Adapter adapter = parent.getAdapter();
HashMap<String, String> map = (HashMap<String, String>) adapter.getItem(position);
Toast toast = Toast.makeText(MainActivity.this, map.get("name") + "-" + map.get("ip"), Toast.LENGTH_SHORT);
toast.show();
}
}); }
}

4.3 滚动条控件

ScrollView                     可滚动的布局容器

参考:
<Android笔记-常用控件以及用法>
<Android开发学习之五、基本界面控件>

Android控件介绍的更多相关文章

  1. Android自定义控件1--自定义控件介绍

    Android控件基本介绍 Android本身提供了很多控件比如我们常用的有文本控件TextView和EditText:按钮控件Button和ImageButton状态开关按钮ToggleButton ...

  2. android xml 常用控件介绍

    android常用控件介绍 ------文本框(TextView)     ------列表(ListView)     ------提示(Toast)     ------编辑框(EditText) ...

  3. Android support library支持包常用控件介绍(二)

    谷歌官方推出Material Design 设计理念已经有段时间了,为支持更方便的实现 Material Design设计效果,官方给出了Android support design library ...

  4. Android控件系列之RadioButton&RadioGroup(转)

    学习目的: 1.掌握在Android中如何建立RadioGroup和RadioButton 2.掌握RadioGroup的常用属性 3.理解RadioButton和CheckBox的区别 4.掌握Ra ...

  5. android控件的属性

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

  6. Android控件TextView的实现原理分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8636153 在前面一个系列的文章中,我们以窗口 ...

  7. Android控件之ImageSwticher

    Android控件之ImageSwticher 1. ImageSwticher介绍 ImageSwitcher是图片切换的控件,它能实现图片切换时的动画效果,包括图片导入效果.图片消失效果等等.An ...

  8. 一步一步学android控件(之六) —— MultiAutoCompleteTextView

    今天学习的控件是MultiAutoCompleteTextView . 提到MultiAutoCompleteTextView 我们就自然而然地想到AutoCompleteTextView ,就想知道 ...

  9. Android控件点击事件

    1. 介绍 本文介绍了Android控件的点击事件 Android控件点击(onClick)事件可以用如下三种方式来实现 2. 实现onClick方法 在layout的xml中指定onClick方法, ...

随机推荐

  1. P1338 末日的传说 逆序数对

    题目描述 只要是参加jsoi活动的同学一定都听说过Hanoi塔的传说:三根柱子上的金片每天被移动一次,当所有的金片都被移完之后,世界末日也就随之降临了. 在古老东方的幻想乡,人们都采用一种奇特的方式记 ...

  2. python正则表达式01--贪心算法和非贪心算法findall()

    import re st = 'asdfasxxixxdafqewxxlovexxsadawexxyouxxas' # . #点匹配除换行符外的任意字符 a0 = re.findall('xx.',s ...

  3. 20145202马超 《Java程序设计》第九周学习总结

    JDBC 数据库本身是个独立运行的应用程序 撰写应用程序是利用通信协议对数据库进行指令交换,以进行数据的增删查找. JDBC(Java DataBase Connectivity)是Java联机数据库 ...

  4. notepad++ 换行技巧 log换行

    有时候,服务器收集上来的日志,格式很乱,看log很难,如下: java.lang.IllegalStateException: BEvent.init() must be call first\n\t ...

  5. python 三目运算

    python中的三目运算: result = a if condition else b #当满足condition返回a否则返回b 三目运算可以使你的代码看起来简洁,且运算高效

  6. gulp批量添加版本号

    要实现的理想效果: "/css/style.css" => "/dist/css/style.css?v=1d87bebe""/js/scrip ...

  7. day04_07-三个函数的区别

    <?php $link = @mysql_connect('localhost','root',''); mysql_query('use test',$link); mysql_query(' ...

  8. PBFT性能会下降? 各种算法的对比。

    PBFT协议在超过100个节点的时候性能会下降 作者:maxdeath 链接:https://www.zhihu.com/question/60058591/answer/173970031 首先要搞 ...

  9. vim使用的一些积累

    vi visual interfacevim vi improved vim模式:编辑模式(命令模式)输入模式末行模式 编辑模式下,zz保存并退出移动光标:(编辑模式)1.逐字符移动 h 左 l 右 ...

  10. poj 2299 归并排序求逆序数 (可做模板)

    Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 48077   Accepted: 17533 Description In ...