android 获取动态生成的view的宽度

    /**
     * 获取动态控件的宽度
     *
     * @param view
     * @return
     */
    public static int getWidth(View view) {
        int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        view.measure(spec, spec);
        return view.getMeasuredWidth();
    }

参考:

https://blog.csdn.net/xiaoshuang516/article/details/51510361

你可能感兴趣的:(android1)