Android 自定义View(三)

绘制篇

java代码:

/** * Created by aierJun on 2017/2/15. */
public class LineView extends View {
    public LineView(Context context) {
        super(context);
    }

    public LineView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public LineView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Paint paint=new Paint();
        paint.setColor(getResources().getColor(R.color.red_hot));
        canvas.drawLine(100,100,200,100,paint);
// super.onDraw(canvas);
        canvas.drawLine(200,100,200,50,paint);
        canvas.drawLine(100,50,200,50,paint);
        canvas.drawLine(100,50,100,100,paint);
    }
}

Layout代码:

 <com.aierjun.test.view.LineView
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

注意:Paint及Canvas的详细方法请参阅以下

点击直接跳转地址

http://www.cnblogs.com/menlsh/archive/2012/11/18/2776003.html

你可能感兴趣的:(控件)