一、引入布局

  在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 控件知识点的更多相关文章

  1. Android 控件知识点,

    一.Android控件具有visibility属性,可以取三个值:visible(默认值)可见,invisible(不可见,但仍然占据原有的位置和大小,可以看做是变得透明了),gone(空间不仅不可见 ...

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

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

  3. [Android Pro] android控件ListView顶部或者底部也显示分割线

    reference to  :  http://blog.csdn.net/lovexieyuan520/article/details/50846569 在默认的Android控件ListView在 ...

  4. Android控件Gridview实现仿支付宝首页,Fragment底部按钮切换和登录圆形头像

    此案例主要讲的是Android控件Gridview(九宫格)完美实现仿支付宝首页,包含添加和删除功能:Fragment底部按钮切换的效果,包含四个模块,登录页面圆形头像等,一个小项目的初始布局. 效果 ...

  5. Android 控件架构及View、ViewGroup的测量

    附录:示例代码地址 控件在Android开发的过程中是必不可少的,无论是我们在使用系统控件还是自定义的控件.下面我们将讲解一下Android的控件架构,以及如何实现自定义控件. 1.Android控件 ...

  6. Android - 控件android:ems属性

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

  7. UIAutomator定位Android控件的方法

    UIAutomator各种控件定位的方法. 1. 背景 使用SDK自带的NotePad应用,尝试去获得在NotesList那个Activity里的Menu Options上面的那个Add note菜单 ...

  8. 从Android系统出发,分析Android控件构架

    从Android系统出发,分析Android控件构架 Android中所有的控件追溯到根源,就是View 和ViewGroup,相信这个大家都知道,但是大家也许会不太清楚它们之间的具体关系是什么,在A ...

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

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

随机推荐

  1. 【五子棋AI循序渐进】——开局库

    首先,对前面几篇当中未修复的BUG致歉,在使用代码时请万分小心…………尤其是前面关于VCF\VCT的一些代码和思考,有一些错误.虽然现在基本都修正了,但是我的程序还没有经过非常大量的对局,在这之前,不 ...

  2. LeetCode Count of Range Sum

    原题链接在这里:https://leetcode.com/problems/count-of-range-sum/ 题目: Given an integer array nums, return th ...

  3. mybatis父子表批量插入

    <!--父子表批量插入 --> <insert id="insertBatch" parameterType="com.niwopay.dto.beni ...

  4. jenkins创建job不能用中文问题

    Your Container doesn't use UTF-8 to decode URLs. If you use non-ASCII characters as a job name etc,  ...

  5. Advanced REST client

    好用的测试工具,老是忘记名字chrome插件 Advanced REST client

  6. 深入SpringBoot:自定义Endpoint

    前言 上一篇文章介绍了SpringBoot的PropertySourceLoader,自定义了Json格式的配置文件加载.这里再介绍下EndPoint,并通过自定EndPoint来介绍实现原理. En ...

  7. js验证手机号输入是否符合规则

    function isPhone(phone){ var myreg = /^(((13[0-9]{1})|15[0-9]{1}|17[0-9]{1}|185|18[0-9]{1})+\d{8})$/ ...

  8. ExtJs、Struts2、Hibernate3.2登录页面的简单实现

    1.思想的大致模型 2.建立数据库test和数据库表tb_user 1 CREATEDATABASE `test`; 2  CREATETABLE `test`.`tb_user` ( 3 `user ...

  9. winform 计算器

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. BJFU 1034

    描述 对于任意的两个非负整数a,b(0<=a,b<10000),请计算a^b各位数字的和的各位数字的和-- 输入 输入两个非负整数a,b(0<=a,b<10000),注意哦,输 ...