Android examples for User Interface:Layout
move View by Layout Parameters
//package com.java2s; import android.view.View; import android.widget.RelativeLayout.LayoutParams; public class Main { public static LayoutParams moveFrom(View v, LayoutParams params, int leftRight, int upDown) { params = cloneParams(params);/*w ww.j ava 2 s . c o m*/ params.leftMargin += leftRight; params.rightMargin -= leftRight; params.topMargin -= upDown; params.bottomMargin += upDown; v.setLayoutParams(params); 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; } }