自定义MyTextView

package com.example.calsses;


import com.example.shu_ku.R;
import com.example.shu_ku.R.color;
import com.example.shu_ku.R.dimen;


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.CornerPathEffect;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.util.AttributeSet;
import android.widget.TextView;

//这都是最最基础的,留以备忘
public class MyView extends TextView {
private Paint paint;
private int line_color;
private float line_height;


public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.my_view);
line_color = a.getColor(R.styleable.my_view_line_color, color.textColor_hui);
line_height = a.getDimension(R.styleable.my_view_line_height, 1);


paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(line_height);
PathEffect effect = new CornerPathEffect(10);
paint.setPathEffect(effect);
}


//ksdljkdlgmkdfl


@Override
protected void onDraw(Canvas canvas) {
// 绘制一个几何形状
super.onDraw(canvas);
paint.setAntiAlias(true);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(line_height);
CornerPathEffect effect = new CornerPathEffect(10);
paint.setPathEffect(effect);
Path path = new Path();
path.moveTo(10, 15);
path.lineTo(5, 10);


path.lineTo(2, 4);
path.lineTo(3, 6);


path.lineTo(7, 8);
path.lineTo(10, 10);
path.lineTo(10, 2);
path.lineTo(getWidth() - 2, 2);
path.lineTo(getWidth() - 2, getHeight() - 2);
path.lineTo(10, getHeight() - 2);
path.close();


canvas.drawPath(path, paint);
}


}



//涉及到的xml

<?xml version="1.0" encoding="utf-8"?>
<resources>


    <declare-styleable name="my_view">
        <attr name="line_color" format="color" />
        <attr name="line_height" format="dimension" />
    </declare-styleable>


</resources>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值