Center Inhalt des TextView-vertikal & horizontal - LinearLayout

Ich versuche, um die Mitte der Kontext einer TextView horizontal und vertikal. Bitte siehe den folgenden screenshot.

Center Inhalt des TextView-vertikal & horizontal - LinearLayout

Den TextViews, die sagen 1-5 und 100+ Points sind die, die ich soll vertikal zentriert und horizontal. Wie Sie sehen können, sind Sie center-horizontal, aber nicht vertikal. Unten ist der code, den ich verwende.

    <LinearLayout
        android:id="@+id/linearlayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"   
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView 
                android:id="@+id/l1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:paddingTop="5dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:paddingBottom="5dp"
                android:textSize="12sp"
                android:gravity="center_vertical|center_horizontal" /> 

            <TextView 
                android:id="@+id/g1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:paddingTop="5dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:paddingBottom="5dp"
                android:textSize="12sp"
                android:gravity="center_vertical|center_horizontal" /> 

            <TextView 
                android:id="@+id/c1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:paddingTop="5dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:paddingBottom="5dp"
                android:textSize="12sp"
                android:gravity="center_vertical|center_horizontal" />
        </LinearLayout>

Wieder, diese Frage ist wie die Mitte der Inhalt des TextViews, nicht wie Mitte der TextViews im LinearLayout. Also, wie ich Mitte der Inhalt in beide Richtungen in die TextViews?

  • Versuchen android:layout_gravity. Auch, beobachten Sie Ihre Eltern Höhe. Wenn es nur Packungen der Inhalt der Positionierung könnte keine Wirkung haben.
  • verwenden height=match_parent, so dass alle Elemente die gleiche Höhe und können zentriert werden, oder die Schwerkraft=center in Ihrer horizontalen layout.
InformationsquelleAutor Matt | 2013-11-18
Schreibe einen Kommentar