Align text to the right Android, and Android vertical-align TextView is very easy to do. We can do it programmatically or by 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
Check This: আউটসোসিং কি? Outsourcing থেকে কিভাবে ইনকাম করবেন?
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" android:background="#3F51B5" > <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); } }
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 −
Read More:
Also Check:
- What is the Substation?
- TOP 100 SCHOOLS IN BANGLADESH IN 2022
- Microsoft Excel Basic Functions
- CPA Marketing
- How to Fix Account warning on TikTok?
- 20 Best All-Inclusive, Adult-Only Resorts in the World
- 7 Top Economics Magazines, Publications & Journals in 2022
Check Us on Social Media: Facebook, Twitter, Instagram, Pinterest, Linkedin
Pingback: Image Switcher in Android Example - Bangla Skill