Gets the view's LayoutParams and sets it's width & height. - Android User Interface

Android examples for User Interface:Layout

Description

Gets the view's LayoutParams and sets it's width & height.

Demo Code


//package com.java2s;

import android.view.View;

public class Main {
    /** Gets the view's LayoutParams and sets it's width & height. Accepts either
     * LayoutParams.MATCH_PARENT / WRAP_CONTENT or pixel values*/
    public static void setSquareViewDimens(View view, int edgeLength) {
        setViewDimens(view, edgeLength, edgeLength);
    }/*w  w w  .  ja  va  2 s.  co m*/

    /** Gets the view's LayoutParams and sets it's width & height. Accepts either
     * LayoutParams.MATCH_PARENT / WRAP_CONTENT or pixel values*/
    public static void setViewDimens(View view, int width, int height) {
        android.view.ViewGroup.LayoutParams params = view.getLayoutParams();
        params.width = width;
        params.height = height;
        view.setLayoutParams(params);
    }
}

Related Tutorials