Android examples for User Interface:View
move View Center To
//package com.java2s; import android.view.View; import android.view.ViewGroup.MarginLayoutParams; public class Main { public static void moveViewCenterTo(View view, int x, int y) {//?xmllefttopmargin int width = view.getWidth(); int height = view.getHeight(); MarginLayoutParams params = (MarginLayoutParams) view .getLayoutParams();// w ww. j a va2 s . com params.leftMargin = x - width / 2; params.topMargin = y - height / 2; view.setLayoutParams(params); } }