2016-12-09 4 views
0

Ich habe ein Problem mit android:layout_gravity="center" in LinearLayout. Ich lege Text oben und wenn ich ihn in die obere Mitte verschieben möchte, bewegt er es in die Mitte des Telefons und nicht in die obere Mitte.Android Layout Schwerkraft Zentrum horizontal

<?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

Antwort

0

Versuchen android:layout_gravity="center_horizontal" statt android:layout_gravity="center" in der Innenansicht verwenden.

Der Wert center betrifft beide Achsen, während Sie nur auf der X-Achse arbeiten möchten.

Sie können weitere Details here finden.

Verwandte Themen