0

I have a problem with android:layout_gravity="center" in LinearLayout. I put text in the top and when I want to move it to the top center he moves it to the center of the phone and not to the up center.

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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"
   android:background="@drawable/c19669a65794159b935e89fac1d08080"
    tools:context="com.example.hanan.myfirstapp.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="First Exemple"
        android:textColorLink="@android:color/background_light"
        android:textColor="@android:color/background_light"
        android:textSize="24sp"
        android:layout_gravity="center"
        android:id="@+id/textView" />

</LinearLayout>

1

manfcas
  • 1,933
  • 7
  • 28
  • 47
Hanan Sabag
  • 29
  • 2
  • 8

1 Answers1

0

Try using android:layout_gravity="center_horizontal" instead of android:layout_gravity="center" in the inner view.

The value center affects both axis, while you want to work only on the X one.

You can find more details here.

manfcas
  • 1,933
  • 7
  • 28
  • 47