Android examples for User Interface:View Center
convert View Center Position Left Top Position
import android.content.Context; import android.util.DisplayMetrics; import android.util.Log; import android.view.View; public class Main{ /**/* www . j a v a2s . co m*/ * * @param w view's width * @param h view's height * @param centerX target center position x * @param centerY target center position y * @return */ public static float[] convertCenterPosition2LeftTopPosition(float w, float h, float centerX, float centerY) { Log.d(LOG_TAG, "w: " + w + ", h: " + h); float x = centerX - w / 2; float y = centerY - h / 2; return new float[] { x, y }; } }