get View Measured Height - Android User Interface

Android examples for User Interface:View Size

Description

get View Measured Height

Demo Code


//package com.java2s;

import android.view.View;

public class Main {

    public static int getViewMeasuredHeight(View view) {
        calcViewMeasure(view);//www. java2 s .c o m
        return view.getMeasuredHeight();
    }

    public static void calcViewMeasure(View view) {
        int width = View.MeasureSpec.makeMeasureSpec(0,
                View.MeasureSpec.UNSPECIFIED);
        int expandSpec = View.MeasureSpec.makeMeasureSpec(
                Integer.MAX_VALUE >> 2, View.MeasureSpec.AT_MOST);
        view.measure(width, expandSpec);
    }
}

Related Tutorials