Java tutorial
//package com.java2s; import android.view.View; import android.widget.LinearLayout; import android.widget.RelativeLayout.LayoutParams; public class Main { public static void setWeight(View view, float weight, int orientation) { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); if (params == null) { if (orientation != LinearLayout.VERTICAL) { params = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT); } else { params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 0); } } params.weight = weight; view.setLayoutParams(params); } }