Android——ViewGroup的一个用法实例(转载)
找了很久,终于找到了。
<?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的一个用法实例(转载)的更多相关文章
- Android 只开启一个Activity实例
在一个Activity中,多次调用startActivity()来启动另一个Activity,要想只生成一个Activity实例,方法有两种. 方法一:设置起动模式 一个Activity有四种启动模式 ...
- (转)Android 只开启一个Activity实例
在一个Activity中,多次调用startActivity()来启动另一个Activity,要想只生成一个Activity实例,方法有两种. 方法一:设置起动模式 一个Activity有四种启动模式 ...
- Android学习之BitMap用法实例
下面简单说明了BitMap的用法: 从服务器下载一张图片,显示在ImageView控件上,并将该图片保存在移动设备的SD上. // 根据网络URL获取输入流 public InputStream ge ...
- android:ellipsize省略文字用法(转载)
转自:http://zhangkun716717-126-com.iteye.com/blog/864989 TextView及其子类,当字符内容太长显示不下时可以省略号代替未显示的字符:省略号可以在 ...
- 怎么通过activity里面的一个按钮跳转到另一个fragment(android FragmentTransaction.replace的用法介绍)
即:android FragmentTransaction.replace的用法介绍 Fragment的生命周期和它的宿主Activity密切相关,几乎和宿主Activity的生命周期一致,他们之间最 ...
- monkey测试===Android测试工具Monkey用法简介(转载)
Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中.它向系统发送伪随机的用户事件流(如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序进行压力测试.Monkey ...
- Android 操作系统的内存回收机制(转载)
Android 操作系统的内存回收机制(转载) Android APP 的运行环境 Android 是一款基于 Linux 内核,面向移动终端的操作系统.为适应其作为移动平台操作系统的特殊需要,谷歌对 ...
- 【转】Android各种Adapter的用法
转自:http://my.oschina.net/u/658933/blog/372151 Android各种Adapter的用法 发表于5个月前(2015-01-27 10:56) 阅读(143 ...
- android application类的用法
android application类的用法 Application是android系统Framework提供的一个组件,它是单例模式(singleton),即每个应用只有一个实例,用来存储系统的一 ...
随机推荐
- linux下expect使用教程
一.expect介绍 Expect是Unix系统中用来进行自动化控制和测试的软件工具,由DonLibes制作,作为Tcl脚本语言的一个扩展,应用在交互式软件中如telnet,ftp,Passwd,fs ...
- Codeforces Educational Codeforces Round 15 D. Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- [POJ] #1005# I Think I Need a Houseboat : 浮点数运算
一. 题目 I Think I Need a Houseboat Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 97512 ...
- 第二百三十六天 how can I 坚持
太冷了,羽绒服没帽子,冻的耳朵疼. 她今天没有上班,原来是调休了. 其实应该是想到点啥,就应该写下,到晚上写就又忘了,什么都不记得了,这就是个需求吧. 睡觉.
- c语言typedef的用法-解惑阿!很多天书般的东西解释的不错(转)
转自(http://www.cnblogs.com/wchhuangya/archive/2009/12/25/1632160.html) 一.基本概念剖析 int* (*a[5])(int, cha ...
- centos下安装mysql不能启动
初学者犯了个错误:yum安装mysql的命令是:yum -y install mysql-server,而不是yum -y install mysql ----------------------以下 ...
- css3 动画demo
1)http://www.yyyweb.com/demo/css-cokecan/inner.html 2)页面切换效果demo http://www.yyyweb.com/demo/page-tra ...
- Codeforces 100548F - Color (组合数+容斥)
题目链接:http://codeforces.com/gym/100548/attachments 有n个物品 m种颜色,要求你只用k种颜色,且相邻物品的颜色不能相同,问你有多少种方案. 从m种颜色选 ...
- 手把手教你玩转SOCKET模型之重叠I/O篇(下)
四. 实现重叠模型的步骤 作 了这么多的准备工作,费了这么多的笔墨,我们终于可以开始着手编码了.其实慢慢的你就会明白,要想透析重叠结构的内部原理也许是要费点功夫,但是只是学会 如何来使用它,却 ...
- Unity3d:加载Gif格式图片
unity里不支持Gif格式的图片,网上搜索也没有相关资料,殊不知我们已经太相信度娘了,而没有了自己的分析,我们知道Gif图是由多个静态图做成的,那我们就回归本土,第一步:把gif拆成n个静态图放在集 ...