2011-10-06 93 views
9

我有1個線性佈局,裏面有1個表格佈局,裏面有2個表格行,每行內部有2個文字瀏覽。每個textwiev都有9.png.format的背景,看起來像一個按鈕。如何使TextView具有相同的大小,而不管文本內部如何

如何讓這些文字瀏覽器的所有文字大小相同,使背景圖像的尺寸相同?

這是我做媒體鏈接:

<LinearLayout android:layout_height="fill_parent" 
       android:gravity="bottom" 
       android:layout_width="fill_parent" 
       android:layout_weight="2"> 
<TableLayout android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:stretchColumns="0 1"> 
      <TableRow android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:layout_weight="1" 
         android:padding="2dp"> 
         <TextView android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:background="@drawable/answer_small_off" 
            android:layout_weight="1" 
            android:text="@string/hello" 
            android:gravity="center" 
            android:id="@+id/main_text_answer1" 
            android:lines="3" 
            android:maxLines="3" 
            android:textSize="10dp" android:minLines="3" android:minEms="20" android:maxEms="20" android:ems="20"> 
         </TextView> 
         <TextView android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:background="@drawable/answer_small_off" 
            android:layout_weight="1" 
            android:text="@string/hello" 
            android:gravity="center" 
            android:id="@+id/main_text_answer2" 
            android:lines="3" 
            android:maxLines="3" 
            android:textSize="10dp"> 
         </TextView> 
      </TableRow> 
      <TableRow android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="2dp"> 
         <TextView android:layout_width="fill_parent" 
           android:layout_height="fill_parent" 
           android:background="@drawable/answer_small_off" 
           android:layout_weight="1" 
           android:text="@string/hello" 
           android:gravity="center" 
           android:id="@+id/main_text_answer3" 
           android:lines="3" 
           android:maxLines="3" 
           android:textSize="10dp"> 
         </TextView> 
         <TextView android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:background="@drawable/answer_small_off" 
            android:layout_weight="1" 
            android:text="@string/hello" 
            android:gravity="center" 
            android:id="@+id/main_text_answer4" 
            android:lines="3" 
            android:maxLines="3" 
            android:textSize="10dp"> 
         </TextView> 

      </TableRow> 
      </TableLayout> 
      </LinearLayout> 

BTW。這只是一個屏幕的一部分,但其餘的並不重要,我認爲

+0

CRO, 我似乎有一個類似的情況,並在我自己解決它[答案](http://stackoverflow.com/questions/7698397/textview-height-increase-when-decreasing-font-size/7707447#7707447) –

回答

4

所有你需要做的是改變Layout_height和Layout_width這樣的:

    <TextView android:layout_width="149dp" 
           android:layout_height="50dp" 
           android:background="@drawable/answer_small_off" 
           android:layout_weight="1" 
           android:text="@string/hello" 
           android:gravity="center" 
           android:id="@+id/main_text_answer1" 
           android:lines="3" 
           android:maxLines="3" 
           android:textSize="10dp" android:minLines="3" android:minEms="20" android:maxEms="20" android:ems="20"> 
        </TextView> 
+1

但我做這個應用程序的多種屏幕類型,我正在做一個測驗應用程序,這些都是答案按鈕,所以不會在其他屏幕上出現問題嗎?= –

+0

它可以做,值得一試去看。否則,你可以使用填充父:android:layout_width =「FILL_PARENT」 –

+2

好的,我添加了android:minEms =「20」android:ems =「20」android:ems =「20」 ,但高度依然在變化,視線有多少 –

相關問題