draw Padding on Canvas for View - Android Graphics

Android examples for Graphics:Canvas

Description

draw Padding on Canvas for View

Demo Code


//package com.java2s;

import android.graphics.Canvas;

import android.graphics.Paint;
import android.graphics.Rect;

import android.view.View;

public class Main {
    private static final int PADDING_COLOR = 0x883366FF;

    public static void drawPadding(View view, Canvas canvas) {
        int width = view.getWidth();
        int height = view.getHeight();
        int lPad = view.getPaddingLeft();
        int tPad = view.getPaddingTop();
        int rPad = view.getPaddingRight();
        int bPad = view.getPaddingBottom();

        Rect lRect = new Rect(0, 0, lPad, height);
        Rect tRect = new Rect(lPad, 0, width - rPad, tPad);
        Rect rRect = new Rect(width - rPad, 0, width, height);
        Rect bRect = new Rect(lPad, height - bPad, width - rPad, height);
        Paint paint = new Paint();
        paint.setColor(PADDING_COLOR);/*from  w w  w .j  a  va  2  s  . co  m*/
        canvas.drawRect(lRect, paint);
        canvas.drawRect(tRect, paint);
        canvas.drawRect(rRect, paint);
        canvas.drawRect(bRect, paint);
    }
}

Related Tutorials