2013-02-20 72 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