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. 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. xml for table layout sample.
<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. For eg : StringABCDEFGHIJKLM
can become 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%.
You could also refer to this : Android Holo theme does not wrap multiple line spinner dropdown items
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.