set GridLayout Params Wrap - Android User Interface

Android examples for User Interface:Layout

Description

set GridLayout Params Wrap

Demo Code


import android.support.v7.widget.GridLayout;
import android.view.View;
import android.view.ViewGroup;

public class Main{
    public static <T extends View> void setGridLayoutParamsWrap(T view) {
        setGridLayoutParams(view, ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
    }/*  ww  w  .j  a v a  2s.c  o  m*/
    public static <T extends View> void setGridLayoutParams(T view,
            int width, int height, int left, int top, int right, int bottom) {
        GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
        layoutParams.width = width;
        layoutParams.height = height;
        layoutParams.setMargins(left, top, right, bottom);
        view.setLayoutParams(layoutParams);
    }
    public static <T extends View> void setGridLayoutParams(T view,
            int widthAndHeight, int left, int top, int right, int bottom) {
        setGridLayoutParams(view, widthAndHeight, widthAndHeight, left,
                top, right, bottom);
    }
    public static <T extends View> void setGridLayoutParams(T view,
            int width, int height) {
        setGridLayoutParams(view, width, height, 0, 0, 0, 0);
    }
    public static <T extends View> void setGridLayoutParams(T view,
            int widthAndHeight) {
        setGridLayoutParams(view, widthAndHeight, widthAndHeight);
    }
}

Related Tutorials