convert View Center Position Left Top Position - Android User Interface

Android examples for User Interface:View Center

Description

convert View Center Position Left Top Position

Demo Code


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 };
    }
}

Related Tutorials