package com.cky.learnandroiddetails;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by cuikangyuan on 16/7/5.
 * 自绘控件
 */
public class CounterView extends View implements View.OnClickListener{

    private Paint mPaint;

    private Rect mBounds;

    private int mCount;

    public CounterView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mBounds = new Rect();
        setOnClickListener(this);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPaint.setColor(Color.BLUE);
        canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint);
        mPaint.setColor(Color.YELLOW);
        mPaint.setTextSize(30);
        String text = String.valueOf(mCount);
        mPaint.getTextBounds(text, 0, text.length(), mBounds);
        float textWidth = mBounds.width();
        float textHeight = mBounds.height();
        canvas.drawText(text, getWidth()/2 - textWidth/2, getHeight()/2+textHeight/2, mPaint);
    }

    @Override
    public void onClick(View v) {
        mCount++;
        invalidate();
    }
}

@@ -1318,11 +1318,350 @@
 );%0A    %7D
+%0A%0A    /*%0A    * scrollBy %E5%AE%9E%E9%99%85%E4%B8%8A%E8%B0%83%E7%94%A8%E4%BA%86 scrollTo, %E4%BB%A5%E5%AE%9E%E7%8E%B0%E7%9B%B8%E5%AF%B9%E6%BB%91%E5%8A%A8%0A    * scrollTo%E5%AE%9E%E7%8E%B0%E4%BA%86%E5%9F%BA%E4%BA%8E%E6%89%80%E4%BC%A0%E5%8F%82%E6%95%B0%E7%9A%84%E7%BB%9D%E5%AF%B9%E6%BB%91%E5%8A%A8%0A    *%0A    * %E5%9C%A8%E6%BB%91%E5%8A%A8%E8%BF%87%E7%A8%8B%E4%B8%AD%0A    * mScrollX = View%E5%B7%A6%E8%BE%B9%E7%BC%98View%E5%86%85%E5%AE%B9%E5%B7%A6%E8%BE%B9%E7%BC%98%E5%9C%A8%E6%B0%B4%E5%B9%B3%E6%96%B9%E5%90%91%E7%9A%84%E8%B7%9D%E7%A6%BB%0A    * mScrollY = View%E4%B8%8A%E8%BE%B9%E7%BC%98%E5%92%8CView%E5%86%85%E5%AE%B9%E4%B8%8A%E8%BE%B9%E7%BC%98%E5%9C%A8%E7%AB%96%E7%9B%B4%E6%96%B9%E5%90%91%E7%9A%84%E8%B7%9D%E7%A6%BB%0A    *%0A    * scrollBy scrollTo%E5%8F%AA%E8%83%BD%E6%94%B9%E5%8F%98View%E5%86%85%E5%AE%B9%E7%9A%84%E4%BD%8D%E7%BD%AE%E8%80%8C%E4%B8%8D%E8%83%BD%E6%94%B9%E5%8F%98View%E5%9C%A8%E5%B8%83%E5%B1%80%E4%B8%AD%E7%9A%84%E4%BD%8D%E7%BD%AE%0A    *%0A    * View%E5%B7%A6%E8%BE%B9%E7%BC%98%E5%9C%A8View%E5%86%85%E5%AE%B9%E5%B7%A6%E8%BE%B9%E7%BC%98%E5%8F%B3%E8%BE%B9%E6%97%B6 mScrollX %E6%AD%A3%E5%80%BC%0A    *%0A    * View%E4%B8%8A%E8%BE%B9%E7%BC%98%E5%9C%A8View%E5%86%85%E5%AE%B9%E4%B8%8A%E8%BE%B9%E7%BC%98%E4%B8%8B%E8%BE%B9%E6%97%B6 mScrollY %E6%AD%A3%E5%80%BC%0A    * */
 %0A%7D%0A

更新 View 相关