微调多线项目中选择项目显示上升级Froyo重叠 [英] Spinner with multi-line items overlaps selected item display on Froyo

查看:111
本文介绍了微调多线项目中选择项目显示上升级Froyo重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建纱厂的外观相同的所有版本的Andr​​oid回升级Froyo。为此,我使用 HoloEverywhere 。一些微调项文本的多个行,我想它来包装。

使用默认布局, android.R.layout.simple_spinner_dropdown_item 或<一href="https://github.com/Prototik/HoloEverywhere/blob/master/library/res/layout/simple_spinner_dropdown_item.xml">HoloEverywhere's落替换它的,ellipsizes包裹它的文字。

服用HoloEverywhere的布局,作为一个自定义布局的起点与单线设置为 ellipsize 设置为 layout_height 设置为 WRAP_CONTENT 没有帮助,文本仍然切断。

我的可以的让文字在下拉列表中通过包装的TextView 的LinearLayout ,而在升级Froyo 设备这个食堂在选择项的显示:

此方法能正常工作在较新的设备。下拉项目布局精美的所有设备。但升级Froyo 做这种怪异的文字重叠,当我使用自定义的下拉列表项的布局。每个选择刚刚被堆在最后一个顶部。

这个问题:  <一href="http://stackoverflow.com/questions/14139106/spinner-does-not-wrap-text-is-this-an-android-bug?rq=1">Spinner不换行文字 - 这是一个Android的bug 有关纱厂文本换行显示,只有这样,才能做到这一点是重新从头开始的造型没有继承,但听起来很疯狂,很容易出现问题。

?。

my_simple_list_item_1.xml:

 &LT;的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =300dp
  机器人:layout_height =WRAP_CONTENT&GT;

  &LT;的TextView
    机器人:ID =@ + ID /安卓:text1中
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =50dp
    机器人:ellipsize =金字招牌
    机器人:layout_gravity =center_vertical
    机器人:单线=FALSE/&GT;
&LT; / LinearLayout中&GT;
 

Java的:

 进口org.holoeverywhere.widget.Spinner;

    spinner1.setAdapter(ArrayAdapter.createFromResource(这一点,
            R.array.array_of_strings,R.layout.my_simple_list_item_1));
 

解决方案

我找到了解决办法。该文本被包装为纺纱初始显示只能处理textviews,我已经找到了另一种解决方案推荐使用的线性布局。这使得微调的下拉列表看起来是正确的。事实证明适配器有)称为setDropDownViewResource(资源,它允许您设置不同的视图下拉比什么是显示在飞旋的选择。

 进口org.holoeverywhere.widget.Spinner;

 ArrayAdapter适配器1 = ArrayAdapter.createFromResource(这一点,R.array.array_of_strings,R.layout.simple_list_item_1);
 adapter1.setDropDownViewResource(R.layout.my_simple_list_item_1);
 spQ1.setAdapter(适配器1);
 

在这个例子中simple_list_item是由机器人和mY_simple_list_item是

提供的默认视图

 &LT;的LinearLayout
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =300dp
机器人:layout_height =WRAP_CONTENT&GT;

&LT;的TextView
  机器人:ID =@ + ID /安卓:text1中
  机器人:layout_width =WRAP_CONTENT
  机器人:layout_height =50dp
  机器人:ellipsize =金字招牌
  机器人:layout_gravity =center_vertical
  机器人:单线=FALSE/&GT;

&LT; / LinearLayout中&GT;
 

现在内部微调的下拉列表视图和纺纱文字环绕显示的选择。

I'm trying to create Spinners that look the same on all versions of Android back to Froyo. To that end, I'm using HoloEverywhere. Some of the spinner item text is more than one line, and I'd like it to wrap.

Using the default layout, android.R.layout.simple_spinner_dropdown_item, or HoloEverywhere's drop-in replacement for it, ellipsizes the text instead of wrapping it.

Taking the HoloEverywhere's layout as a starting point for a custom layout with singleLine set to false, ellipsize set to none, and layout_height set to wrap_content doesn't help, the text is still cut off.

I can get the text to wrap correctly in the dropdown by wrapping the TextView in a LinearLayout, but on Froyo devices this messes up the display of the selected item:

This method works fine on newer devices. The dropdown item layouts are fine on all devices. But Froyo does this weird text overlapping when I use a custom dropdown item layout. Each selection just gets piled on top of the last one.

This question: Spinner does not wrap text -- is this an Android bug? about text wrapping in Spinners suggests that only way to do it is recreating the styling from scratch without inheriting, but that sounds crazy and prone to problems.

my_simple_list_item_1.xml:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="300dp"
  android:layout_height="wrap_content" >   

  <TextView
    android:id="@+id/android:text1"
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:ellipsize="marquee"
    android:layout_gravity="center_vertical"
    android:singleLine="false"/>
</LinearLayout> 

Java:

    import org.holoeverywhere.widget.Spinner;

    spinner1.setAdapter(ArrayAdapter.createFromResource(this,
            R.array.array_of_strings, R.layout.my_simple_list_item_1));

解决方案

I found a solution. The text was wrapping as the spinners initial display could only handle textviews, and I had found another solution recommending the use of a linear layout. This made the dropdown of the spinner look correct. As it turns out adapters have a resource called setDropDownViewResource() which allows you to set a different view for the dropdown than what is displayed in the spinner's selection.

 import org.holoeverywhere.widget.Spinner;

 ArrayAdapter adapter1 = ArrayAdapter.createFromResource(this,R.array.array_of_strings,R.layout.simple_list_item_1);
 adapter1.setDropDownViewResource(R.layout.my_simple_list_item_1);
 spQ1.setAdapter(adapter1);

in this example the simple_list_item is the default view supplied by android and mY_simple_list_item is

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="300dp"
android:layout_height="wrap_content" >   

<TextView
  android:id="@+id/android:text1"
  android:layout_width="wrap_content"
  android:layout_height="50dp"
  android:ellipsize="marquee"
  android:layout_gravity="center_vertical"
  android:singleLine="false"/>

</LinearLayout> 

Now the text wraps inside the dropdown view of the spinner AND in the spinners displayed selection.

这篇关于微调多线项目中选择项目显示上升级Froyo重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆