get View Measured Width - Android User Interface

Android examples for User Interface:View Size

Description

get View Measured Width

Demo Code


//package com.java2s;

import android.view.View;

public class Main {

    public static int getViewMeasuredWidth(View view) {
        calcViewMeasure(view);/*from w ww  .ja va 2s.c  o m*/
        return view.getMeasuredWidth();
    }

    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