set View Height - Android User Interface

Android examples for User Interface:View Size

Description

set View Height

Demo Code


//package com.java2s;

import android.view.View;
import android.view.ViewGroup;

public class Main {
    public static void setHeight(View view, int height) {
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        if (null == lp) {
            lp = new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }/* w w  w  . ja v  a 2s  .co  m*/
        lp.height = height;
        view.setLayoutParams(lp);
    }

    public static void setHeight(View view, float height) {
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        if (null == lp) {
            lp = new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        lp.height = (int) height;
        view.setLayoutParams(lp);
    }
}

Related Tutorials