Android examples for User Interface:View Size
measure View Image Half Height
//package com.java2s; import android.view.View; import android.view.ViewGroup.LayoutParams; public class Main { public static void measureImageHalfHeight(View img) { int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); img.measure(w, h);/*w w w .j a v a 2 s. c om*/ int width = img.getMeasuredWidth(); LayoutParams params = img.getLayoutParams(); System.out.println("params.height:" + params.height + " params.width:" + params.width); params.height = width / 2; System.out.println("w:" + w + " h:" + h + " width:" + width + " params.height:" + params.height); img.setLayoutParams(params); } }