2016-12-14 5 views
0

Ich habe eine LinearLayout und ich möchte nur einen Text in der Mitte meiner Bildansicht, die eine Form ist.wie man eine Textansicht innerhalb von Bildansicht android zentrieren

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

     <TextView 
      android:id="@+id/state_area" 
      android:layout_width="wrap_content" 
      android:textColor="#F000" 
      android:layout_height="90dp" 
      android:textSize="40sp" 
      android:layout_marginBottom="24dp" 
      android:layout_gravity="center_horizontal" /> 

    </LinearLayout> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/shape" 
     android:layout_gravity="center" /> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="24dp" 
     android:src="@drawable/shape" 
     android:layout_gravity="center" /> 

</LinearLayout> 

Das Ergebnis bisher:

enter image description here

+0

Verwenden FrameLayout zwei Ansichten wickeln damit –

Antwort

1

Sie könnten einfach eine Textansicht verwenden und die Form als Hintergrund festlegen.

<TextView 
     android:id="@+id/state_area" 
     android:layout_width="wrap_content" 
     android:textColor="#F000" 
     android:layout_height="90dp" 
     android:background="@drawable/shape" 
     android:textSize="40sp" 
     android:layout_marginBottom="24dp" 
     android:layout_gravity="center_horizontal" /> 
+0

fast da, aber der Text ist an der Spitze, nicht in der Mitte –

+0

hinzufügen Schwerkraft = Zentrum –

+0

Vielen Dank !! –

1

Sie Relative Layout verwenden können das Layout übereinander anzuordnen. Oder Sie können einen benutzerdefinierten Kreis als Hintergrund für die Textansicht verwenden

+0

Relative Layout ein Chaos wäre, iwll ich diesen Textview Hintergrund versuchen! –

1
Wrap your image and textview in framelayout 

<LinearLayout 
     android:layout_width="match_parent" 
     android:orientation="vertical" 
     android:layout_height="wrap_content"> 
     <FrameLayout android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <ImageView 

       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="24dp" 
       android:src="@drawable/shape" 
       android:layout_gravity="center" /> 
      <TextView 
       android:id="@+id/state_area" 
       android:layout_width="wrap_content" 
       android:textColor="#F000" 
       android:layout_height="90dp" 
       android:textSize="40sp" 
       android:gravity:"center" 
       android:layout_marginBottom="24dp" 
       android:layout_gravity="center" /> 
     </FrameLayout> 



     <FrameLayout android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="24dp" 
       android:src="@drawable/shape" 
       android:layout_gravity="center" /> 
      <TextView 
       android:id="@+id/state_area2" 
       android:layout_width="wrap_content" 
       android:textColor="#F000" 
       android:layout_height="90dp" 
       android:textSize="40sp" 
       android:gravity:"center" 
       android:layout_marginBottom="24dp" 
       android:layout_gravity="center" /> 
     </FrameLayout> 
    </LinearLayout> 
+0

fast auch dort, aber die Sache ist, der Text ist nicht zentralisiert, und ja an der Spitze –

+0

Gravitations = "Mitte" Textview hinzufügen – pipeur10

Verwandte Themen