0

How can i make a view look like HoneyCombView in Android?

enter image description here

I want to make these type of buttons.

HassanUsman
  • 1,787
  • 1
  • 20
  • 38

1 Answers1

1

Extend ViewGroup, arrange the items in onLayout() and make sure to measure them properly in onMeasure().

You can use this one if it suits you:

    @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int desiredWidth = 100;
    int desiredHeight = 100;

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    int width;
    int height;

    //Measure Width
    if(widthMode == MeasureSpec.EXACTLY) {
        //Must be this size
        width = widthSize;
    } else if(widthMode == MeasureSpec.AT_MOST) {
        //Can't be bigger than...
        width = Math.min(desiredWidth, widthSize);
    } else {
        //Be whatever you want
        width = desiredWidth;
    }

    //Measure Height
    if(heightMode == MeasureSpec.EXACTLY) {
        //Must be this size
        height = heightSize;
    } else if(heightMode == MeasureSpec.AT_MOST) {
        //Can't be bigger than...
        height = Math.min(desiredHeight, heightSize);
    } else {
        //Be whatever you want
        height = desiredHeight;
    }

    //MUST CALL THIS
    setMeasuredDimension(width, height);


    measureChildren(MeasureSpec.makeMeasureSpec(width, widthMode), MeasureSpec.makeMeasureSpec(height, heightMode));
    super.onMeasure(MeasureSpec.makeMeasureSpec(width, widthMode), MeasureSpec.makeMeasureSpec(height, heightMode));
}
Shark
  • 6,513
  • 3
  • 28
  • 50
  • http://stackoverflow.com/questions/23078374/possible-to-make-a-beehive-xml-layout-in-android i want to make look like this but dont know how to use HoneyCombView – HassanUsman Feb 24 '16 at 10:37