没有合适的资源?快使用搜索试试~ 我知道了~
xt, null); } public CustomTitleView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // 获取自定义属性 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomButton); mTitleText = a.getString(R.styleable.CustomButton_titleText); mTitleTextColor = a.getColor(R.styleable.CustomButton_titleText
资源推荐
资源详情
资源评论
























Android自定义自定义View详解详解
主要为大家详细介绍了Android自定义View,帮助大家战胜Android自定义View,为今后的学习打下基础,感兴
趣的小伙伴们可以参考一下
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24252901
很多的Android入门程序猿来说对于Android自定义View,可能都是比较恐惧的,但是这又是高手进阶的必经之路,所有准备
在自定义View上面花一些功夫,多写一些文章。先总结下自定义View的步骤:
1、自定义View的属性
2、在View的构造方法中获得我们自定义的属性
[ 3、重写onMesure ]
4、重写onDraw
我把3用[]标出了,所以说3不一定是必须的,当然了大部分情况下还是需要重写的。
1、自定义、自定义View的属性,首先在的属性,首先在res/values/ 下建立一个下建立一个attrs.xml ,, 在里面定义我们的属性和声明我们的整个样式。在里面定义我们的属性和声明我们的整个样式。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="titleText" format="string" />
<attr name="titleTextColor" format="color" />
<attr name="titleTextSize" format="dimension" />
<declare-styleable name="CustomTitleView">
<attr name="titleText" />
<attr name="titleTextColor" />
<attr name="titleTextSize" />
</declare-styleable>
</resources>
我们定义了字体,字体颜色,字体大小3个属性,format是值该属性的取值类型:
一共有:string,color,demension,integer,enum,reference,float,boolean,fraction,flag;不清楚的可以google一把。
然后在布局中声明我们的自定义View
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res/com.example.customview01"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.example.customview01.view.CustomTitleView
android:layout_width="200dp"
android:layout_height="100dp"
custom:titleText="3712"
custom:titleTextColor="#ff0000"
custom:titleTextSize="40sp" />
</RelativeLayout>
一定要引入 xmlns:custom="http://schemas.android.com/apk/res/com.example.customview01"我们的命名空间,后面
的包路径指的是项目的package
2、在、在View的构造方法中,获得我们的自定义的样式的构造方法中,获得我们的自定义的样式
/**
* 文本
*/
private String mTitleText;
/**
* 文本的颜色
*/
private int mTitleTextColor;
/**
* 文本的大小
*/
private int mTitleTextSize;
/**
* 绘制时控制文本绘制的范围
*/
private Rect mBound;
private Paint mPaint;
public CustomTitleView(Context context, AttributeSet attrs)
{
this(context, attrs, 0);
资源评论


weixin_38604653
- 粉丝: 3
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 浅论网络时代的高校思想政治工作.docx
- Project-Management-Plan-Template-项目管理计划模板.doc
- 项目管理经验交流材料.docx
- 工程认证背景下软件项目管理企业捐课模式分析.docx
- 物联网对计算机通信网络的影响及问题研究.docx
- 计算机在人事管理中的应用.docx
- 论述基层文物保护信息化建设存在的问题与解决对策.docx
- (源码)基于Python的智能家居自动化系统.zip
- 互联网金融企业财务管理中存在的问题及对策.docx
- 第四章企业会计信息化及其流程重组.doc
- 物联网在智慧校园中的应用分析.docx
- 大数据时代企业管理会计的机遇与挑战.docx
- 计算机网络远程控制系统及应用研究.docx
- 互联网+时代高职《外贸英语函电》多模态教学探究.docx
- 下一代通信网络的无线传输技术研究.doc
- 大数据一期课程中的机器学习相关内容
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
