Android 控件知识点
一、引入布局
在xml文件中引入另一个布局
<include layout="@layout/XXX" />
个人理解就是在父布局的某个位置在嵌套一个布局。
二、自定义控件
步骤:
2.1 新建一个xml文件,做好自定义控件
例如:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:layout_weight="1"
android:layout_gravity="center"
android:layout_margin="5dip"
android:background="#0f0f0f"
android:textColor="#fff000"
android:text="back"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="24sp"
android:textColor="#fff000"
android:layout_weight="1"
android:id="@+id/text2"
android:text="小麦麦"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:textColor="#fff000"
android:layout_weight="1"
android:id="@+id/button4"
android:text="edit"/> </LinearLayout>
2.2 新建一个Class,继承自View类或者其子类。例如:
public class TittleLayout extends LinearLayout {
public TittleLayout(Context context, AttributeSet attrs) {
super(context, attrs);
((LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.button,this);
}
} 2.3 在布局中引入控件就会调用该控件的构造函数,重写自定义控件父类的构造函数,并在构造函数中借助LayoutInflater加载布局文件的xml。
2.4 在布局文件中添加自定义控件
添加自定义控件与普通控件一样,只不过需要指明控件的完整类名。
例如:
<com.example.zds.test_menu01.TittleLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Android 控件知识点的更多相关文章
- Android 控件知识点,
一.Android控件具有visibility属性,可以取三个值:visible(默认值)可见,invisible(不可见,但仍然占据原有的位置和大小,可以看做是变得透明了),gone(空间不仅不可见 ...
- Android控件TextView的实现原理分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8636153 在前面一个系列的文章中,我们以窗口 ...
- [Android Pro] android控件ListView顶部或者底部也显示分割线
reference to : http://blog.csdn.net/lovexieyuan520/article/details/50846569 在默认的Android控件ListView在 ...
- Android控件Gridview实现仿支付宝首页,Fragment底部按钮切换和登录圆形头像
此案例主要讲的是Android控件Gridview(九宫格)完美实现仿支付宝首页,包含添加和删除功能:Fragment底部按钮切换的效果,包含四个模块,登录页面圆形头像等,一个小项目的初始布局. 效果 ...
- Android 控件架构及View、ViewGroup的测量
附录:示例代码地址 控件在Android开发的过程中是必不可少的,无论是我们在使用系统控件还是自定义的控件.下面我们将讲解一下Android的控件架构,以及如何实现自定义控件. 1.Android控件 ...
- Android - 控件android:ems属性
Android - 控件android:ems属性http://blog.csdn.net/caroline_wendy/article/details/41684255?utm_source=tui ...
- UIAutomator定位Android控件的方法
UIAutomator各种控件定位的方法. 1. 背景 使用SDK自带的NotePad应用,尝试去获得在NotesList那个Activity里的Menu Options上面的那个Add note菜单 ...
- 从Android系统出发,分析Android控件构架
从Android系统出发,分析Android控件构架 Android中所有的控件追溯到根源,就是View 和ViewGroup,相信这个大家都知道,但是大家也许会不太清楚它们之间的具体关系是什么,在A ...
- Android控件系列之RadioButton&RadioGroup(转)
学习目的: 1.掌握在Android中如何建立RadioGroup和RadioButton 2.掌握RadioGroup的常用属性 3.理解RadioButton和CheckBox的区别 4.掌握Ra ...
随机推荐
- ASP.NET Global Application_Error事件中访问Session报错 解决
报错信息:会话状态在此上下文中不可用 protected void Application_Error(object sender, EventArgs e) { //以此判断是否可用Session ...
- JavaMail接、收邮件
我总算把这个研究出来啦.... 不要觉得 代码有点多哈. 我们先来说发送邮箱吧,首先建立一个属性文件*.properties sys.properties server=smtp.163.com ## ...
- win8.1蓝屏解决
按Windows 徽标键 +X键,点击“命令提示符(管理员)”,复制以下命令并运行: SFC /SCANNOW (此命令需要一段时间完成,不要关闭它,即使进度看上去停止不动.) reg add &qu ...
- CentOS7 安装与配置Ant
安装前提:需安装jdk(java-1.8.0-openjdk-devel). 1.到官网下载Antt包,我下的是:apache-ant-1.9.7-bin.tar.gz 2.解压缩 tar -zxvf ...
- video和audio
1.video 使用: <video width="320" height="240" src="http://www.jb51.net/mov ...
- 最近面试的题目(WEB、Service、SQL、JavaScript)
整理一下最近面试被问到的主要题目.由于本人主要是做WEB及WEB SERVICE这块,使用的语言主要是C#,数据库主要用到的也是MSSQL.所以就分成这些块来整理(有些是在面试之后才意识到回答不对), ...
- Hadoop+Spark:集群环境搭建
环境准备: 在虚拟机下,大家三台Linux ubuntu 14.04 server x64 系统(下载地址:http://releases.ubuntu.com/14.04.2/ubuntu-14.0 ...
- 从零开始学Linux[二]:常用操作:用户组、进程、网络、ssh
摘要:Linux基础学习:创建用户组和用户.软件包管理.磁盘管理.进程管理.前后台进程的切换.网络配置.浏览网页.远程登录ssh 第一节,主要介绍一些简单命令,这节介绍一些日常操作. 1.创建用户组和 ...
- Number类型方法
//1.toString(); 转换成字符串 var s=123; console.log(typeof s.toString()); //string //2.toLocaleString() ...
- Java面试题问与答——编译时与运行时
在开发和设计的时候,我们需要考虑编译时,运行时以及构建时这三个概念.理解这几个概念可以更好地帮助你去了解一些基本的原理.下面是初学者晋级中级水平需要知道的一些问题. Q.下面的代码片段中,行A和行B所 ...