Central alignment appears correctly in the Activity preview, but not when running the app?

Asked

Viewed 359 times

0

I put alignment to the center for all textView and in the preview of Activity, still in android studio, all right:

inserir a descrição da imagem aqui

But when I run the app the same doesn’t happen:

inserir a descrição da imagem aqui

Even if you set the layout_width of the textViews as math_parent for them to hide all the extension of the device in the horinzontal, did not obtain the expected result:

inserir a descrição da imagem aqui

xlm from Activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:customfontdemo="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="genesysgeneration.font2.MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="fonte padraum" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/textView"
        android:layout_marginTop="159dp"
        android:gravity="center"
        android:text="********** asdasd **********" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/textView2"
        android:layout_marginTop="118dp"
        android:gravity="center"
        android:text="TextView\nasdlaslkdj\nasodjaosdjoa" />

</RelativeLayout>

  • 1

    To align them you need to use Gravity: put this in your textview android:gravity="center" that will center

  • Where is your code?

  • With the instructions of @Armandomarquessobrinho I managed to solve Ack Lay, so I will put the code

  • opa! that’s right friend Dummy Sinforoso, but I positively answered @Thiago Leon because she is correct.

  • there is some difference between Gravity center and center_horizontal?

  • 1

    Symphonic doll the center_horizontal puts the content in the middle of the screen but in its position at the height ja the center it leaves the content centered in the middle of the screen and in the middle of the height

Show 1 more comment

1 answer

2


Use the Following code in your textviews

android:gravity = "center" to center horizontally and vertically in its function, if you want a specific centering as horizontal would be android:gravity="center_horizontal"

if you would like more information on the subject https://developer.android.com/reference/android/view/Gravity.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.