Drawable / GradientDrawable 等 相關api

一 Drawable setBounds()

     注: Drawable.setBounds(int left,int top,int right,int bottom);    四邊   永遠平行座標系x   y

     參數一  left  爲矩形左側距離y座標系的距離   top爲矩形區域上方距離x座標系的距離   right 爲  右側 y座標系距離的距離

                   bottom 爲矩形下方距離x座標系的距離 

     方法 1:gradientDrawable.setBounds(RectF r);   傳入矩形區域

     方法2 :Drawable.setBounds(int left,int top,int right,int bottom);  傳入上下左右座標點  形成矩形區域

     作用:這個四參數 或 RectF   指的是drawable將在被繪製在canvas的哪個矩形區域內。

     例子:

 @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = canvas.getWidth();
        int height = canvas.getHeight();
        canvas.translate(400, 400);
        // 繪製座標線
        mPaint.setColor(Color.RED);
        canvas.drawLine(0, 0, width, 0, mPaint);
        //繪製藍色Y軸
        mPaint.setColor(Color.BLUE);
        canvas.drawLine(0, 0, 0, height, mPaint);
        canvas.translate(0,10);
        mPaint.setColor(Color.RED);
        canvas.drawLine(0,0,100,0,mPaint);

        // 設置gradientDrawable將被繪製在哪個矩形區域內
        gradientDrawable.setBounds(10, 10, 100, 100);
        gradientDrawable.draw(canvas);
    }

  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章