GroupView 组合控件
来源:互联网 发布:淘宝店需要营业执照 编辑:程序博客网 时间:2024/05/19 02:02
../values/attr.xml 配置属性
<?xml version="1.0" encoding="utf-8"?><resources> <declare-styleable name="LevelMenuItemView"> <attr name="text" format="string"></attr> <attr name="text_size" format="dimension"></attr> <attr name="text_color" format="color"></attr> <attr name="img_src" format="reference"></attr> <attr name="img_width" format="dimension"></attr> <attr name="img_heigh" format="dimension"></attr> </declare-styleable></resources>
../view/GroupView.java
public class LevelMenuItemView extends LinearLayout { public LevelMenuItemView(Context context) { super(context, null); } public LevelMenuItemView(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater layoutInflater = (LayoutInflater) context. getSystemService(Context.LAYOUT_INFLATER_SERVICE); layoutInflater.inflate(R.layout.level_menu_item, this); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.LevelMenuItemView); initView(typedArray); } }
初始化控件,配置属性:
ImageView img_top; TextView tv_title; private void initView(TypedArray typedArray) { tv_title = (TextView) findViewById(R.id.tv_title); tv_title.setText(typedArray.getString(R.styleable.LevelMenuItemView_text)); tv_title.setTextSize(typedArray.getDimension(R.styleable.LevelMenuItemView_text_size, 12)); tv_title.setTextColor(typedArray.getColor(R.styleable.LevelMenuItemView_text_color, 0xffffffff)); img_top = (ImageView) findViewById(R.id.img_top); img_top.setImageResource(typedArray.getResourceId(R.styleable.LevelMenuItemView_img_src, 0)); int width = (int) typedArray.getDimension(R.styleable.LevelMenuItemView_img_width, 25); int heigh = (int) typedArray.getDimension(R.styleable.LevelMenuItemView_img_heigh, 25); LayoutParams params = new LayoutParams(width, heigh); img_top.setLayoutParams(params); typedArray.recycle(); }
绑定点击事件:
public void setImageOnclick(final OnItemImageClick onclick) { img_top.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onclick.click(v); } }); } public interface OnItemImageClick { public void click(View view); }
.main.xml 文件中使用
< 重点: 添加该自定义控件的命名空间 >
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:linc="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#eee" android:orientation="horizontal" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"> <com.mjc.slidebackdemo.android.view.demo.groupView.LevelMenuItemView android:id="@+id/item1" android:layout_width="70dp" android:layout_height="80dp" linc:img_heigh="48dp" linc:img_src="@mipmap/xiaoshidai" linc:img_width="48dp" linc:text="item1" linc:text_color="#80fa8072" linc:text_size="12sp" /> <com.mjc.slidebackdemo.android.view.demo.groupView.LevelMenuItemView android:id="@+id/item2" android:layout_width="70dp" android:layout_height="80dp" linc:img_heigh="48dp" linc:img_src="@mipmap/xiangjiankang" linc:img_width="48dp" linc:text="item2" linc:text_color="#80fa8072" linc:text_size="12sp" /> <com.mjc.slidebackdemo.android.view.demo.groupView.LevelMenuItemView android:id="@+id/item3" android:layout_width="70dp" android:layout_height="80dp" linc:img_heigh="48dp" linc:img_src="@mipmap/zhidemai" linc:img_width="48dp" linc:text="item3" linc:text_color="#80fa8072" linc:text_size="12sp" /></LinearLayout>
0 0
- GroupView 组合控件
- 【Unity 3D】学习笔记八:GroupView控件(群组视图)
- 组合控件
- 自定义控件-组合控件
- 自定义组合控件,组合模式
- 自定义圆形的groupView
- 自定义控件之组合控件
- Android自定义控件--组合控件
- android 控件 自定义组合控件
- 自定义控件之组合控件
- 自定义控件之组合控件
- 组合框控件
- Windows 组合框控件
- 组合框控件(combobox)
- 组合框控件(combobox)
- 封装一些组合控件
- 组合框控件CComboBox
- 组合框控件
- Android View 事件分发机制详解
- 使用Gson解析复杂的json数据
- 动态计算文字的高度
- CSS3 常用属性总结
- glassfish安装mysql数据库connector/J
- GroupView 组合控件
- OP-TEE笔记之OPTEE__OS文件结构
- 查看oracle表空间
- sqlplus中var和print的使用
- RHEL7密码恢复
- iOS开发网络篇—HTTP协议
- 1.Two Sum
- 彻底解决PHP Session不过期以及SessionId保持不变的问题
- 打印较长的json数据Log