Java tutorial
//package com.java2s; import android.view.View; import android.view.ViewGroup; public class Main { public static void setWidth(View view, int width) { if (view == null || view.getLayoutParams() == null) { throw new IllegalArgumentException("View LayoutParams is null"); } ViewGroup.LayoutParams params = view.getLayoutParams(); params.width = width; view.setLayoutParams(params); } }