简体   繁体   English

Android表格布局格式问题不适合屏幕

[英]Android table layout formatting problems not fitting to screen

i am using tablelayout with 3 columns lable, * and spinner, which all of that has wrap_content and it works fine when the spinner text is small. 我正在使用带有3列标签,*和微调器的tablelayout,所有这些都具有wrap_content,并且在微调器文本较小时效果很好。 if any one of the spinner has very long text then all the spinner extents till the end and also it is not fitting to the screen. 如果任何一个微调框的文本都非常长,则所有微调框的范围一直到结束,并且也不适合屏幕。

is there any way to make each spinner to fit to its text size like wrap_content inside tablelayout. 有什么方法可以使每个微调器适合其文本大小,如tablelayout中的wrap_content。 xml for table layout sample. 表布局示例的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>

i hope many would have come across the same problem. 我希望很多人会遇到同样的问题。 Thanks in advance 提前致谢

You can either set maxWidth attribute for each spinner or you can check the length of the string ie to be placed in spinner in case if its length > x (say 10) then use substring fn to take only (x-3) characters from the string and suffix it with " ... " and place that string in spinner. 您可以为每个微调器设置maxWidth属性,也可以检查字符串的长度,即如果其长度> x(例如10),则放置在微调器中,然后使用子字符串fn从字符串中仅取(x-3)个字符字符串并在其后缀“ ...”,然后将该字符串放入微调框。 For eg : StringABCDEFGHIJKLM can become StringAB... . 例如: StringABCDEFGHIJKLM可以变成StringAB...

This is because you are stretching only column 2 which is the spinner. 这是因为您仅拉伸了第二列,即旋转器。 You would have to set a weight on each of the columns. 您将必须在每个列上设置权重。 Something like 就像是

<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>

A weight would indicate the % of the screen to occupy. 权重将指示要占据的屏幕百分比。 so each of the textViews would take 20% of the screen and the spinner would take 60%. 因此每个textView将占据屏幕的20%,旋转器将占据60%。

You could also refer to this : Android Holo theme does not wrap multiple line spinner dropdown items 您也可以参考以下内容: Android Holo主题不包含多行微调框下拉项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM