Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    public static int getViewWidth(View view) {
        if (view != null) {
            int width = view.getMeasuredWidth();
            if (width == 0) {
                LayoutParams params = view.getLayoutParams();
                if (params != null && params.width > 0) {
                    return params.width;
                }
                view.measure(0, 0);
                width = view.getMeasuredWidth();
            }
            return width;
        }
        return 0;
    }
}