找了很久,终于找到了。

<?xml version="1.0" encoding="UTF-8" ?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:okCancelBar="http://schemas.android.com/apk/res/com.example.android.merge">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
android:src="@drawable/golden_gate" />
<com.example.android.merge.OkCancelBar android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:paddingTop="8dip"
android:gravity="center_horizontal"
android:background="#AA000000"
okCancelBar:okLabel="Save"
okCancelBar:cancelLabel="Don't save"
/>
</merge>

com.example.android.merge.OkCancelBar是一个自定义的GROUP

public class OkCancelBar extends LinearLayout{

    public OkCancelBar(Context context,AttributeSet attrs){

        super(context, attrs);

        setOrientation(HORIZONTAL);

        setGravity(Gravity.CENTER);

        setWeightSum(1.0f);

        LayoutInflater.from(context).inflate(R.layout.okcancelbar,this,true);

        TypedArray array= context.obtainStyledAttributes(attrs, R.styleable.OkCancelBar,0,0);

        String text= array.getString(R.styleable.OkCancelBar_okLabel);

        if(text==null) text="Ok";

        ((Button) findViewById(R.id.okcancelbar_ok)).setText(text);
text= array.getString(R.styleable.OkCancelBar_cancelLabel); if(text==null) text="Cancel"; ((Button) findViewById(R.id.okcancelbar_cancel)).setText(text); array.recycle(); }
}

LayoutInflater.from(context).inflate(R.layout.okcancelbar,this,true);

直接从XML中得到一个VIEW加入到当前GROUP中

okcancelbar.xml:

<merge xmlns:android="http://schemas.android.com/apk/res/android">

<include layout="@layout/okcancelbar_button"  android:id="@+id/okcancelbar_ok"/>
<include layout="@layout/okcancelbar_button" android:id="@+id/okcancelbar_cancel"/> </merge>

Android——ViewGroup的一个用法实例(转载)的更多相关文章

  1. Android 只开启一个Activity实例

    在一个Activity中,多次调用startActivity()来启动另一个Activity,要想只生成一个Activity实例,方法有两种. 方法一:设置起动模式 一个Activity有四种启动模式 ...

  2. (转)Android 只开启一个Activity实例

    在一个Activity中,多次调用startActivity()来启动另一个Activity,要想只生成一个Activity实例,方法有两种. 方法一:设置起动模式 一个Activity有四种启动模式 ...

  3. Android学习之BitMap用法实例

    下面简单说明了BitMap的用法: 从服务器下载一张图片,显示在ImageView控件上,并将该图片保存在移动设备的SD上. // 根据网络URL获取输入流 public InputStream ge ...

  4. android:ellipsize省略文字用法(转载)

    转自:http://zhangkun716717-126-com.iteye.com/blog/864989 TextView及其子类,当字符内容太长显示不下时可以省略号代替未显示的字符:省略号可以在 ...

  5. 怎么通过activity里面的一个按钮跳转到另一个fragment(android FragmentTransaction.replace的用法介绍)

    即:android FragmentTransaction.replace的用法介绍 Fragment的生命周期和它的宿主Activity密切相关,几乎和宿主Activity的生命周期一致,他们之间最 ...

  6. monkey测试===Android测试工具Monkey用法简介(转载)

    Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中.它向系统发送伪随机的用户事件流(如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序进行压力测试.Monkey ...

  7. Android 操作系统的内存回收机制(转载)

    Android 操作系统的内存回收机制(转载) Android APP 的运行环境 Android 是一款基于 Linux 内核,面向移动终端的操作系统.为适应其作为移动平台操作系统的特殊需要,谷歌对 ...

  8. 【转】Android各种Adapter的用法

    转自:http://my.oschina.net/u/658933/blog/372151 Android各种Adapter的用法 发表于5个月前(2015-01-27 10:56)   阅读(143 ...

  9. android application类的用法

    android application类的用法 Application是android系统Framework提供的一个组件,它是单例模式(singleton),即每个应用只有一个实例,用来存储系统的一 ...

随机推荐

  1. 数往知来 三层架构 <十四>

    三层架构_1 一.三层 就是把程序的各个部分都分离,尽量的底耦合,做到分工明确.责任明确 第一层:Dal   数据访问层 第二层 :Bll  业务逻辑判断层 第三层: UI   界面显示层 比如说数据 ...

  2. java多线程之Lock线程同步

    1.线程同步: package cn.itcast.heima2; import java.util.concurrent.locks.Lock; import java.util.concurren ...

  3. RVM 安装&下载Ruby

    1. #查看当前ruby版本 2. $ ruby -v 3. ruby 1.8.7 4. #列出已知的ruby版本 5. $ rvm list known 6. #安装ruby 1.9.3 7. $ ...

  4. [POJ] #1006# Biorhythms : 最小公倍数/同余问题

    一. 题目 Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 127263   Accepted: 403 ...

  5. jq 写法

    <!doctype html> <html> <head> <meta charset="utf-8"> <script sr ...

  6. ajax 新闻栏目

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  7. windows下揪出java程序占用cpu很高的线程 并找到问题代码 死循环线程代码

    我的一个java程序偶尔会出现cpu占用很高的情况 一直不知道什么原因 今天终于抽时间解决了 系统是win2003 jvisualvm 和 jconsole貌似都只能看到总共占用的cpu 看不到每个线 ...

  8. jspace2d——A free 2d multiplayer space shooter

    http://code.google.com/p/jspace2d/ —————————————————————————————————————————————————————————————— We ...

  9. IE8-模拟script onerror

    利用VBScript 检测,有副作用,慎用! var loadScript = function () { var DOC = document, HEAD = document.getElement ...

  10. Dependency Injection学习笔记

    component把需要依赖者(CoffeeMaker)和供应提供者(Heater, Pump)联系起来 使用 区别:上的的依赖是内部创建的,下面的依赖是外面传进来的 注入方式