工具
Android
Android
Java
Eclipse
3.07MB
源码下载地址:http://www.devstore.cn/code/info/679.html
源码简介
在网上找到的一个小例子,是关于自定义控件的。有这方面需求的可以拿去研究一下。
源码运行截图
运行截图
运行截图
运行截图
源码片段
- public MyImageView(Context context, AttributeSet attrs) {
- super(context, attrs);
- // TODO Auto-generated constructor stub
- int resourceId = -1;
- TypedArray typedArray = context.obtainStyledAttributes(attrs,
- R.styleable.MyImageView);
- ImageView iv = new ImageView(context);
- TextView tv = new TextView(context);
- int N = typedArray.getIndexCount();
- for (int i = 0; i < N; i++) {
- int attr = typedArray.getIndex(i);
- switch (attr) {
- case R.styleable.MyImageView_Oriental:
- resourceId = typedArray.getInt(
- R.styleable.MyImageView_Oriental, 0);
- this.setOrientation(resourceId == 1 ? LinearLayout.HORIZONTAL
- : LinearLayout.VERTICAL);
- break;
- case R.styleable.MyImageView_Text:
- resourceId = typedArray.getResourceId(
- R.styleable.MyImageView_Text, 0);
- tv.setText(resourceId > 0 ? typedArray.getResources().getText(
- resourceId) : typedArray
- .getString(R.styleable.MyImageView_Text));
- break;
- case R.styleable.MyImageView_Src:
- resourceId = typedArray.getResourceId(
- R.styleable.MyImageView_Src, 0);
- iv.setImageResource(resourceId > 0 ?resourceId:R.drawable.ic_launcher);
- break;
- }
- }
- addView(iv);
- addView(tv);
- typedArray.recycle();
- }