Align Text to the Right Android & Vertical TextView Without Programmatically in 2023 [Java]

Align text to the right Android, and Android vertical align TextView is very easy to do. We can do it programmatically or by the hard code. In this article, I will show you Align text to the right android from the XML. It doesn’t matter if you use Kotlin or Java. You can do it for both platforms.

For Center Vertical in RelativeLayout: You can simply use this for vertically centered.

android:gravity="center_vertical"

For center horizontal in RelativeLayout: You can simply use this for horizontally center.

android:gravity="center_horizontal"

Full Code of Align Text to the Right Android & Vertical Align TextView

Step 1: Open Android Studio. Click on File > New Project. Enter the details about the new project.

Step2: Add the following code to res/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:textColor="#FFFFFF"
        android:text="Text in Center Vertical" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:text="Welcome to Voltage Lab - Text in Center Horizontal"
        android:textColor="#FFFFFF" />
</RelativeLayout>

Step 3: Add the following code to src/MainActivity.java

package com.example.androidverticalaligntextview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Step 4  − Add the following code to Manifests/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.androidverticalaligntextview">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AndroidVerticalAlignTextview"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:theme="@style/Theme.AppCompat.Light"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

We will try to run the application. I am assuming that you have connected your actual Android mobile device with your computer.

To run the Android Studio app, click the Run icon.

Select your mobile device as an option and then check your mobile device which will display your default screen −

align text to the right android

If you have any questions regarding align text to the right android then please let us know in the comments. We love to help you.

Read More:

Image Switcher in Android Example

Related articles

Android TextView Alignment Justify Without Programmatically in 2023 [Java]

Android TextView Alignment Justify is a nice feature to...

Image Switcher in Android Example Programmatically in 2023 [Java]

You don't always want an image to appear abruptly...

Case Studies

eDental App

Case Study: eDental Dentist App

Our team recently embarked on an exciting project to develop the eDental Dentist App, a cutting-edge mobile application designed for both Android and iOS...

Voltage Lab SAAS App

Voltage Lab wanted to launch a new SAAS app that would allow students to enjoy educational material with freemium features. We developed a custom...
google play app store listing

Keyword Research for EEE & Cricket Live Score App

A Cricket Live Score App & EEE Engineer App aimed to enhance their visibility on Google and the iOS app store, seeking to rank...