2016-04-28 19 views
-1

Edit: Sorry es war ein Problem in meiner Implementierung, das Layout Gewicht war nicht 1 und damit das Problem. Es funktionierte, nachdem ich das Layout Weight repariert habe.Android: Text zentriert nicht in TextView?

Ich weiß nicht warum, aber ich bin nicht in der Lage, Text in diesem custom TextView zu zentrieren, kann jemand bitte helfen. Ich habe verschiedene Dinge ausprobiert, aber keine funktioniert. Das Symbol in meiner IconTextView ist näher rechts und nicht in der Mitte. Vielen Dank !!

<LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.25"> 

      <com.malinskiy.materialicons.widget.IconTextView 
        xmlns:app="http://schemas.android.com/apk/res-auto" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:background="@drawable/ripple_effect" 
        android:gravity="center" 
        android:text="{zmdi-play}" 
        android:textColor="#ffffff" 
        android:textSize="40dp" 
        app:hacky_preview="true" /> 
    </LinearLayout> 
+0

Screenshot freigeben. –

Antwort

0

Try

android:textAlignment="gravity" 

zu Ihrem IconTextView Elemente

0

Es ist keine richtige Lösung, aber hinzuzufügen, da vielleicht das Problem bei der Umsetzung des IconTextView ist, könnten Sie versuchen, die IconTextView Einstellung mit wrap_content und Zentrierung der gesamten IconTextView innerhalb der Verpackung LinearLayout. Etwas wie folgt aus:

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="0.25" 
    android:gravity="center"> 

    <com.malinskiy.materialicons.widget.IconTextView 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:background="@drawable/ripple_effect" 
      android:text="{zmdi-play}" 
      android:textColor="#ffffff" 
      android:textSize="40dp" 
      app:hacky_preview="true" /> 
</LinearLayout> 
0

Sie Textansicht in relativ relativen Layout wie

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
> 

<com.malinskiy.materialicons.widget.IconTextView 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:background="@drawable/ripple_effect" 
     android:text="{zmdi-play}" 
     android:textColor="#ffffff" 
     android:textSize="40dp" 
     app:hacky_preview="true" /> 
</RelativeLayout> 

Hope this helfen Ihnen

+0

kann dies nicht tun, ich verwende Layout-Gewichte – varunkr

+0

Sie können relative Layout innerhalb linearer Layout hinzufügen. Und dann kann Gewicht zu linearen Layout zuweisen. – sukhbir

0
<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <com.malinskiy.materialicons.widget.IconTextView 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/ripple_effect" 
       android:gravity="center" 
       android:text="{zmdi-play}" 
       android:textColor="#ffffff" 
       android:textSize="40dp" 
       app:hacky_preview="true" /> 
</LinearLayout> 

Versuchen Sie dies unter Code verwenden können .. kann Ihnen helfen ..

+0

danke, bitte beachten Sie die Änderung. – varunkr

Verwandte Themen