2012-12-11 36 views
1

這看起來像一個微不足道的問題,但我發現在小布局中對齊TextView是件痛苦的事情。 下面是XML: 在一個小的LinearLayout中對齊TextView中心

<LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/button_bg_phone" 
       android:gravity="center_vertical" 
       android:orientation="horizontal"> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/icon_phone" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:layout_marginLeft="4dp" 
        android:shadowColor="#88FFFFFF" 
        android:shadowDx="0" 
        android:shadowDy="1" 
        android:shadowRadius="0.2" 
        android:textColor="#6d5013" 
        android:textSize="24sp" /> 
</LinearLayout> 

背景圖像是9patch,所以有填充,但文本不居中和被切斷。我會張貼輸出圖像,但顯然這被認爲是垃圾郵件。我嘗試了多種方法,但仍然存在。較小的文字確實改善了圖像的居中,但只有非常小的文字居中。任何想法爲什麼?

回答

0

嘗試這樣

<LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/button_bg_phone"> 
<TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="fitCenter" 
       android:shadowColor="#88FFFFFF" 
       android:shadowDx="0" 
       android:shadowDy="1" 
       android:shadowRadius="0.2" 
       android:textColor="#6d5013" 
       android:textSize="24sp" /> 

+0

scaleType不是TextView中的一個屬性。我確實試圖把layoutHeight =「matchParent」,但問題仍然存在。 – LightSystem

相關問題