Android examples for User Interface:Layout
get Move Layout Params
//package com.java2s; import android.view.View; import android.widget.RelativeLayout.LayoutParams; public class Main { public static LayoutParams getMoveParams(View v, int upDown, int leftRight) { LayoutParams original = (LayoutParams) v.getLayoutParams(); //RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(original); LayoutParams params = cloneParams(original); params.leftMargin += leftRight;/*from www. j a va 2 s. co m*/ params.rightMargin -= leftRight; params.topMargin -= upDown; params.bottomMargin += upDown; return params; } public static LayoutParams cloneParams(LayoutParams params) { LayoutParams copy = new LayoutParams(params.width, params.height); copy.leftMargin = params.leftMargin; copy.topMargin = params.topMargin; copy.rightMargin = params.rightMargin; copy.bottomMargin = params.bottomMargin; int[] rules = params.getRules(); for (int i = 0; i < rules.length; i++) { copy.addRule(i, rules[i]); } copy.setMarginStart(params.getMarginStart()); copy.setMarginEnd(params.getMarginEnd()); return copy; } }