2013-02-20 73 views
0

我使用tablelayout與3列標籤,*和微調,這一切都有wrap_content和它工作正常時,微調文本很小。如果任何一個微調器有很長的文本,那麼所有的微調器都會擴展到最後,並且它不適合屏幕。Android桌面佈局格式問題不適合屏幕

是否有任何方法讓每個微調器適合其文本大小,比如tablelayout中的wrap_content。 xml表格佈局示例。

<TableLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#FFFFFF" 
     android:stretchColumns="2" > 
     <TableRow> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_column="0" 
       android:gravity="right" 
       android:paddingLeft="3dip" 
       android:text="Sold To" 
       android:textColor="#000033" 
       android:textSize="17sp" /> 

      <TextView 
       android:layout_column="1" 
       android:gravity="left" 
       android:text="*" 
       android:textColor="#FF0000" 
       android:textSize="17sp" 
       android:width="20dip" /> 

      <Spinner 
       android:id="@+id/sold_to_dd" 
       android:layout_width="wrap_content" 
       android:layout_column="2" 
       /> 
     </TableRow> 


    </TableLayout> 

我希望很多人都會遇到同樣的問題。在此先感謝

+1

你能粘貼你的佈局文件嗎? – 2013-02-20 05:50:22

回答

0

您可以爲每個微調器設置maxWidth屬性,或者您可以檢查字符串的長度,即如果其長度大於x(比如說10),則使用子字符串fn只取( x-3)字符並將其後綴爲「...」並將該字符串放置在微調器中。例如:StringABCDEFGHIJKLM可以變成StringAB...

+0

感謝您可以發佈代碼,在哪裏檢查條件 – saran 2013-02-20 06:13:01

+0

您必須對要添加到微調器中的每個字符串執行子字符串操作。如果使用'ArrayList'填充微調器,則在將每個字符串添加到微調器之前對其進行子字符串操作 – user2041902 2013-02-20 06:38:58

0

這是因爲你只拉伸了第2列,它是微調器。你將不得不在每個列上設置權重。類似於

<TableLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#FFFFFF" > 
    <TableRow> 

     <TextView 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:layout_column="0" 
      android:gravity="right" 
      android:paddingLeft="3dip" 
      android:text="Sold To" 
      android:textColor="#000033" 
      android:textSize="17sp" /> 

     <TextView 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:layout_column="1" 
      android:gravity="left" 
      android:text="*" 
      android:textColor="#FF0000" 
      android:textSize="17sp" /> 

     <Spinner 
      android:id="@+id/sold_to_dd" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="6" 
      android:layout_column="2" 
      android:singleLine="true" 
      /> 
    </TableRow> 


</TableLayout> 

重量將指示佔用屏幕的百分比。所以每個textView會佔用屏幕的20%,而微調器會佔用60%。

你也可以參考這個:Android Holo theme does not wrap multiple line spinner dropdown items