Calculates the fetched width of the given ViewGroup layout in pixels. - Android User Interface

Android examples for User Interface:ViewGroup

Description

Calculates the fetched width of the given ViewGroup layout in pixels.

Demo Code


//package com.java2s;

import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;

public class Main {
    /**/*w w  w .  j  av  a  2s  .c  o  m*/
     * Calculates the fetched width of the given layout in pixels.
     * 
     * @param aLayout
     *            The layout to measure.
     * @return the height of the given layout.
     */
    public static int calcWidth(final ViewGroup aLayout) {
        final LayoutParams params = aLayout.getLayoutParams();
        final int width = params.width;
        params.width = LayoutParams.WRAP_CONTENT;
        aLayout.measure(0, 0);
        final int measuredWidth = aLayout.getMeasuredWidth();
        params.width = width;
        return measuredWidth;
    }
}

Related Tutorials