android自定义View (五)view.requestLayout() 与 invalidate()

一。要点

  1. If in the course of processing the event, the view's bounds may need to be changed, the view will call requestLayout().

  2. Similarly, if in the course of processing the event the view's appearance may need to be changed, the view will call invalidate().

  3. If either requestLayout() or invalidate() were called, the framework will take care of measuring, laying out, and drawing the tree as appropriate.

 

二。实例

 

    public void setSwitchTypeface(Typeface tf) {
        if (mTextPaint.getTypeface() != tf) {
            mTextPaint.setTypeface(tf);

            requestLayout();
            invalidate();
        }
    }


    public void setSwitchPadding(int pixels) {
        mSwitchPadding = pixels;
        requestLayout();
    }

 

 

 

posted @ 2014-06-13 11:57  等风来。。  Views(479)  Comments(0Edit  收藏  举报
------------------------------------------------------------------------------------------------------------ --------------- 欢迎联系 x.guan.ling@gmail.com--------------- ------------------------------------------------------------------------------------------------------------