自定义组件
来源:互联网 发布:百度大数据预测双色球 编辑:程序博客网 时间:2024/05/19 03:44
<resources> <declare-styleable name="myView"> <attr name="textSize" format="dimension"/> <attr name="textColor" format="color"/> <attr name="text" format="string"/> </declare-styleable></resources>
自定义组件在这里使用:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myandroid="http://schemas.android.com/apk/res/com.ybj.lesson" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="列表" android:id="@+id/bt_list"/> <com.ybj.lesson.MyView android:layout_width="wrap_content" android:layout_height="wrap_content" myandroid:textSize="30sp" myandroid:textColor="#00ff00"> </com.ybj.lesson.MyView></LinearLayout>
自定义组件控制类:
package com.ybj.lesson;import com.ybj.lesson.R;import android.content.Context;import android.content.res.TypedArray;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.util.AttributeSet;import android.view.View;public class MyView extends View { private Paint paint = null;; public MyView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub //取出属性文件 TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.myView); //取出属性 float textSize = array.getDimension(R.styleable.myView_textSize, 25); int textColor = array.getColor(R.styleable.myView_textColor, Color.BLUE); String text = array.getString(R.styleable.myView_text); paint = new Paint(); paint.setColor(textColor); paint.setTextSize(textSize); //关闭资源 array.recycle(); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); //绘制组件内容 canvas.drawText("aaaa", 10, 30, paint); canvas.drawCircle(10, 20, 6, paint); }}
0 0
- 自定义组件
- 自定义组件
- 自定义组件
- 自定义组件
- 自定义组件
- 自定义组件
- 自定义组件
- 自定义组件
- 自定义组件
- 自定义组件
- 自定义组件
- 自定义组件
- 自定义组件
- view 自定义组件 --- 水滴组件
- 动态改变自定义组件!
- 创建JSF自定义组件
- 创建JSF自定义组件
- WEB自定义数据组件
- 对话屏幕Dynpro(SE51) 屏幕元素 屏幕属性 PAI事件的触发、屏幕元素Function Code设置 屏幕流逻辑Screen Flow Logic 对话屏幕中的字段命名大小写问题
- 制作网站缩略标志
- 数据多自动往上滚动
- Geolocation 地理定位
- 黑马程序员——Java高新技术---反射
- 自定义组件
- PHP后门新玩法:一款猥琐的PHP后门分析
- 华为OJ中级题-字符串合并处理
- Spiral Matrix
- opencv_traincascade的使用学习
- JSTL标签库核心标签C标签的使用
- 交换button中图片和按钮的位置
- HTML 颜色
- javascript正则表达式