Java tutorial
//package com.java2s; //License from project: Apache License import android.annotation.TargetApi; import android.os.Build; import android.text.Layout; import android.view.Gravity; import android.widget.TextView; public class Main { @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static Layout.Alignment getLayoutAlignment(TextView textView) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { return Layout.Alignment.ALIGN_NORMAL; } Layout.Alignment alignment; switch (textView.getTextAlignment()) { case TextView.TEXT_ALIGNMENT_GRAVITY: switch (textView.getGravity() & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.START: alignment = Layout.Alignment.ALIGN_NORMAL; break; case Gravity.END: alignment = Layout.Alignment.ALIGN_OPPOSITE; break; case Gravity.LEFT: alignment = (textView.getLayoutDirection() == TextView.LAYOUT_DIRECTION_RTL) ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_NORMAL; break; case Gravity.RIGHT: alignment = (textView.getLayoutDirection() == TextView.LAYOUT_DIRECTION_RTL) ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_OPPOSITE; break; case Gravity.CENTER_HORIZONTAL: alignment = Layout.Alignment.ALIGN_CENTER; break; default: alignment = Layout.Alignment.ALIGN_NORMAL; break; } break; case TextView.TEXT_ALIGNMENT_TEXT_START: alignment = Layout.Alignment.ALIGN_NORMAL; break; case TextView.TEXT_ALIGNMENT_TEXT_END: alignment = Layout.Alignment.ALIGN_OPPOSITE; break; case TextView.TEXT_ALIGNMENT_CENTER: alignment = Layout.Alignment.ALIGN_CENTER; break; case TextView.TEXT_ALIGNMENT_VIEW_START: alignment = Layout.Alignment.ALIGN_NORMAL; break; case TextView.TEXT_ALIGNMENT_VIEW_END: alignment = Layout.Alignment.ALIGN_OPPOSITE; break; case TextView.TEXT_ALIGNMENT_INHERIT: // default: alignment = Layout.Alignment.ALIGN_NORMAL; break; } return alignment; } }