get Circular Outline and return ViewOutlineProvider - Android User Interface

Android examples for User Interface:View Property

Description

get Circular Outline and return ViewOutlineProvider

Demo Code


//package com.java2s;
import android.graphics.Outline;

import android.view.View;
import android.view.ViewOutlineProvider;

public class Main {
    public static ViewOutlineProvider getCicularOutline(final int width,
            final int height) {
        return new ViewOutlineProvider() {
            @Override/* w  w w.jav  a2 s .com*/
            public void getOutline(View view, Outline outline) {
                int size = Math.min(width, height);
                int xOff = (width - size) / 2;
                int yOff = (height - size) / 2;
                //                Log.d(TAG,"w " + width + " h " + height + " x " + xOff + " y " + yOff);
                outline.setOval(xOff, yOff, size, size);
            }
        };
    }

    public static ViewOutlineProvider getCicularOutline() {
        return new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                int width = view.getWidth();
                int height = view.getHeight();
                int size = Math.min(width, height);
                int xOff = (width - size) / 2;
                int yOff = (height - size) / 2;
                //                Log.d(TAG,"w " + width + " h " + height + " x " + xOff + " y " + yOff);
                outline.setOval(xOff, yOff, size, size);
            }
        };
    }
}

Related Tutorials