Adjust the view height to which you want to be. - Android User Interface

Android examples for User Interface:View Size

Description

Adjust the view height to which you want to be.

Demo Code


//package com.java2s;
import android.view.View;
import android.view.ViewGroup.LayoutParams;

public class Main {
    private static final int INDICATOR_KEEP_VIEW_SIZE = -100;

    /**/*  ww w.jav a 2s  .c o  m*/
     * Adjust the view height to which you want to be.
     * 
     * @param view
     *            target view
     * @param height
     *            the height, either {@link LayoutParams#WRAP_CONTENT},
     *            {@link LayoutParams#FILL_PARENT} (replaced by
     *            {@link LayoutParams#MATCH_PARENT} in API Level 8), or a fixed
     *            size in pixels
     */
    public static void adjustViewHeight(View view, int height) {
        adjustViewSize(view, INDICATOR_KEEP_VIEW_SIZE, height);
    }

    /**
     * Adjust the view size (width, height) to which you want to be.
     * 
     * @param view
     *            target view
     * @param width
     *            the width, either {@link LayoutParams#WRAP_CONTENT},
     *            {@link LayoutParams#FILL_PARENT} (replaced by
     *            {@link LayoutParams#MATCH_PARENT} in API Level 8), or a fixed
     *            size in pixels
     * @param height
     *            the height, either {@link LayoutParams#WRAP_CONTENT},
     *            {@link LayoutParams#FILL_PARENT} (replaced by
     *            {@link LayoutParams#MATCH_PARENT} in API Level 8), or a fixed
     *            size in pixels
     */
    public static void adjustViewSize(View view, int width, int height) {
        final View target = view;

        LayoutParams layoutParams = target.getLayoutParams();

        if (width != INDICATOR_KEEP_VIEW_SIZE)
            layoutParams.width = width;

        if (height != INDICATOR_KEEP_VIEW_SIZE)
            layoutParams.height = height;

        target.setLayoutParams(layoutParams);
    }
}

Related Tutorials