2016-02-04 31 views
0

經過這段時間擺弄的時間超過了我不知道承認的情況,文本對齊如何在TextView中工作?Android TextView剔除文字

enter image description here

很顯然,我試圖讓「N」垂直中心本身在TextView的。

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/titleN" 
    android:id="@+id/textView" 
    android:height="114dp" 
    android:textSize="120dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignBottom="@+id/textView3" 
    android:layout_gravity="center" 
    android:gravity="center"/> 

當我刪除的高度,它看起來像:

enter image description here

+0

請張貼顯示您所做的代碼。我們不能告訴你如何解決這個問題,而不知道你在第一時間做了什麼。 –

+0

是因爲'height'小於'textSize'?你根本不需要這個值。 – tallpaul

+0

我嘗試了很多不同的值,試圖讓它與它旁邊的TextViews排隊。我將使用任何值工作... – user1561108

回答

0

的問題是,TextView's height(114dp)text (120dp)本身的尺寸較小,從TextView刪除height屬性,你不不需要這條線

android:height="114dp" // you need to remove this attribute from the TextView 

你需要的是android:gravity="center_vertical"

textview的重心被設定爲center_vertical文本將保持在中心,而不管textView的身高

實施例: -

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical" 
    android:text="N" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

輸出

enter image description here

+0

對我沒有效果。 – user1561108

+0

@ user1561108,你是否刪除了這一行android:height =「114dp」 –

+0

是的,也沒有效果。 – user1561108

0

嘗試使用maring屬性,如margin-top或margin-bottom。如果這不起作用嘗試使用填充,如填充頂部或填充底部