- 浏览: 198827 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
xumin_minzi:
我也在使用ndk编译,ffmpeg源码放在哪个目录里面?
[原创]Android ndkr8编译 FFmpeg 0.11.1 "Happiness" -
ericchan2012:
在Dialog调用show方法之后
【原创】Android 设置Dialog的长宽和位置 -
maohualei:
求解: 我设置的时候 位置居然没有反应 dial ...
【原创】Android 设置Dialog的长宽和位置
自定义组合控件,用来复用
其一:
首先看布局文件:
一张图片,一行文字。
然后看定义的控件:
好了,这样你就可以使用了。
其二:
自定义一个EditText
首先在drawable定义一个selector,命名为selector_edittext_bg:
然后写个自定义控件的xml文件:
这个就是EditText前面有个说明文字;
接下来是定义一个控件了。
下面是使用方法:
好了,完工。具体要了解如何定义自己的属性,请看下面:
http://ericchan2012.iteye.com/admin/blogs/1650900
http://ericchan2012.iteye.com/blog/1650754
其一:
首先看布局文件:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_below="@+id/iv" android:text="@string/bless" /> </RelativeLayout>
一张图片,一行文字。
然后看定义的控件:
public class ImageBtn extends LinearLayout { private ImageView iv; private TextView tv; private LayoutInflater mInflater; public ImageBtn(Context context) { this(context, null); } public ImageBtn(Context context, AttributeSet attrs) { super(context, attrs); mInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); mInflater.inflate(R.layout.birth_cloud_item, this, true); } protected void onFinishInflate() { super.onFinishInflate(); iv = (ImageView) findViewById(R.id.iv); tv = (TextView) findViewById(R.id.tv); } public void setImageResource(int resId) { iv.setImageResource(resId); } public void setText(int resId) { tv.setText(resId); } }
好了,这样你就可以使用了。
其二:
自定义一个EditText
首先在drawable定义一个selector,命名为selector_edittext_bg:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/edit_pressed" android:state_focused="true"/> <item android:drawable="@drawable/edit_normal"/> </selector>
然后写个自定义控件的xml文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> <TextView android:id="@+id/tv" android:textColor="#987787" android:layout_width="100dip" android:layout_height="wrap_content" android:textSize="16sp" android:text="@string/phone" /> <EditText android:id="@+id/et" android:layout_width="180dip" android:background="@drawable/selector_edittext_bg" android:layout_height="wrap_content"/> </LinearLayout>
这个就是EditText前面有个说明文字;
接下来是定义一个控件了。
public class MyEditText extends LinearLayout { private EditText et; private TextView tv; private LayoutInflater mInflater; public MyEditText(Context context) { this(context, null); } public MyEditText(Context context, AttributeSet attrs) { super(context, attrs); mInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); mInflater.inflate(R.layout.myedittext, this, true); } protected void onFinishInflate() { super.onFinishInflate(); et = (EditText) findViewById(R.id.et); tv = (TextView) findViewById(R.id.tv); } public void setText(int resId) { tv.setText(resId); } }
下面是使用方法:
<com.ds.widget.MyEditText android:id="@+id/myedittext" android:layout_width="fill_parent" android:layout_height="wrap_content" />
好了,完工。具体要了解如何定义自己的属性,请看下面:
http://ericchan2012.iteye.com/admin/blogs/1650900
http://ericchan2012.iteye.com/blog/1650754
发表评论
-
android java调用命令行给文件赋权限
2012-09-27 18:18 1600public void chmodFiles(){ Pr ... -
InputStream,String,File相互转化
2012-09-27 18:10 9841. String --> InputStream I ... -
android Uri获取真实路径转换成File的方法
2012-09-27 18:07 1866有的时候要将android uri如content://med ... -
android将路径转化为URI
2012-09-27 18:06 6403如果已經取得了檔案的路徑的字串,那怎麼轉成URI呢? St ... -
如何向android的setting语言列表中添加一门语言(
2012-09-27 12:59 1091如题: 看了下,android2. ... -
android更改暗码
2012-09-26 13:31 1007在Contact应用程序下的SpecialCharSequen ... -
android触屏震动以及震动强度修改
2012-09-26 09:24 3982PhoneWindowManager.java: 在inter ... -
android修改默认语言
2012-09-26 09:24 1450在build/tools/Buildinfo.sh下面 e ... -
android设置默认壁纸
2012-09-25 12:48 15611,动态壁纸 在frameworks\base\core\re ... -
android设置wallpaper
2012-09-25 12:00 1273设置壁纸的代码在 Launcher.java中的case Ad ... -
android Settings中的各个默认设置
2012-09-25 11:07 934在android中,Settings中有许多的默认设置,比如默 ... -
android 调用camera相关操作
2012-09-21 22:11 10151,通过intent调用camera Intent int ... -
android gallery相关操作
2012-09-21 20:11 9571,android调用gallery获取图片 Intent ... -
android中shape
2012-09-15 12:35 7611,作用: 可以在xml中定义图形,并且定义一些效果 2,用法 ... -
android中layer-list
2012-09-15 12:27 10191,作用: 可以将多个图片(图层)按照顺序层叠起来。 2,用法 ... -
android客户端连接人人网之二----获取朋友信息
2012-09-13 15:31 9051,http请求,将paramList发送到http://ap ... -
android客户端连接人人网之二----获取签名
2012-09-13 14:19 1043官方文档: http://dev.xiaonei.com/wi ... -
android客户端连接人人网之一----获取授权
2012-09-13 14:06 1079连接人人网,有两种方法,参考人人网的官网: http://wi ... -
android美化ToggleButton
2012-09-12 09:55 21751、设置XML属性 我们需要设置Toggle ... -
android中SharedPreference的使用
2012-09-08 11:08 875SharedPreference,相信了解过android的同 ...
相关推荐
Android复合控件学习之自定义标题栏;学习自定义属性、接口回调等知识点
通过本示例,初学者可以快速掌握如何自定义Android复合控件的技巧
主要为大家详细介绍了Android自定义复合控件实现通用标题栏,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
现在我们公司得app都是差不多得title,所以抽时间自己撸了个常用得标题栏控件,直接在布局中使用。 不过本人还是推荐使用官方toolbar 等官方 新控件 ,效果太炫了。无奈设计要求这样,所以在这个公司干,为了开发...
自定义复合控件,支持选中效果及点击事件,非常简单的东西,分享一下,一起学习,欢迎指教
复合控件的创建及使用 详见博文http://blog.csdn.net/a87b01c14/article/details/50350405
《Android 群英传》读书笔记:自定义 View 之创建复合控件
相当漂亮的图表控件。包含动画自定义,复合图表,有很强的扩展性。
图书简介: 本书从由总到分,让读者从整体上把握Android体系结构,融入“群英传”这一故事情节,针对...3.6.2 创建复合控件 43 3.6.3 重写View来实现全新的控件 51 3.7 自定义ViewGroup 54 .........................
复合控件CaptionBar主要是针对DataGridView控件而设计,用于灵活定位网格数据和同步显示信息。
6.2.3 复合类型 105 6.2.4 自定义显示位置Toast 106 6.3 对话框 107 6.3.1 文本信息对话框 107 6.3.2 简单列表项对话框 109 6.3.3 单选项列表项对话框 111 6.3.4 复选框列表项对话框 113 6.3.5 复杂布局列表...
4.4.2 创建复合控件 83 4.4.3 创建定制的Widget和控件 86 4.4.4 使用定制的控件 97 4.5 创建和使用菜单 98 4.5.1 Android菜单系统简介 98 4.5.2 定义活动的菜单 100 4.5.3 动态更新菜单项 102 4.5.4 处理...
4.2 View简介 4.2.1 使用View创建Activity(活动)用户界面 4.2.2 Android Widget工具箱 4.3 布局简介 4.4 创建新的View 4.4.1 修改现有的View 4.4.2 创建复合控件 4.4.3 创建定制的Widget和控件 4.4.4 使用定制的控件...
主要向大家介绍了Android画时钟的方法,内容很详细,分享了每一个制作步骤,感兴趣的小伙伴们可以参考一下
Android 自定义切换按钮 获取涵盖此 repo 中代码的教程 通常在创建 Android 应用程序的过程中,开发人员需要创建一个设置页面。... 根据 Android 文档,复合控件允许您“将一个由一组现有控件组成的可
4.4.2 创建复合控件 4.4.3 创建定制的Widget和控件 4.4.4 使用定制的控件 4.5 创建和使用菜单 4.5.1 Android菜单系统简介 4.5.2 定义活动的菜单 4.5.3 动态更新菜单项 4.5.4 处理菜单选择 4.5.5 ...
4.4.2 创建复合控件 4.4.3 创建定制的Widget和控件 4.4.4 使用定制的控件 4.5 创建和使用菜单 4.5.1 Android菜单系统简介 4.5.2 定义活动的菜单 4.5.3 动态更新菜单项 4.5.4 处理菜单选择 4.5.5 ...
3.6.2 创建复合控件 43 3.6.3 重写View来实现全新的控件 51 3.7 自定义View Group 54 3.8 事件拦截机制分析 59 第4章 List View使用技巧 65 4.1 List View常用优化技巧 66 4.1.1 使用View Holder模式提高效率 ...
4.4.2 创建复合控件 4.4.3 创建定制的Widget和控件 4.4.4 使用定制的控件 4.5 创建和使用菜单 4.5.1 Android菜单系统简介 4.5.2 定义活动的菜单 4.5.3 动态更新菜单项 4.5.4 处理菜单选择 4.5.5 子菜单和上下文菜单...
表单控件 复合控件的简单demo 包括listview gridview 等控件的实现