Android TextView text not wrapping within RelativeLayout on version 2.3.3

余生颓废 提交于 2019-12-05 22:22:08

I had the same exact problem. Let me just say that i just recently changed from using the Android 2.3.3 Platform up to Android 4.0.3 platform cause I wanted to take advantage of the Holo themes. So my default theme looked like this.

<style name="mytheme" parent="android:Theme.Holo">
    <item name="android:windowNoTitle">true</item>
</style>

All my textViews looked great on my phone running Android 4.0.3

But when I ran my app in an emulator running Android 2.3.3 none of the textViews wrapped. I googled and googled and pretty much tried every combination of:

  android:inputType="textMultiLine"
  android:scrollHorizontally="false"
  android:ellipsize="none"
  android:layout_weight="1"

Nada. So then I decided to revert to my original theme:

<style name="myapp" parent="android:Theme.Black.NoTitleBar"/>

Viola! TextViews started wrapping again. Go figure. Not a real solution but maybe someone else can shed some light on why.

Richard Le Mesurier

Here's a good related answer showing that you can use a different theme depending on the version of Android it is running on - just create a versioned styles folder.

Answer here: TextView won't break text

I had a similar problem regarding Android 2.3 and 4.x. As cited by @Richard Le Mesurier in an answer to this question, the issue is related to the theme: Android 4.x uses the Holo theme, which doesn't break long lines. The solution, as cited by Richard, is achieved by using versioned styles.

But I've solved the problem without using versioned styles by adding two properties to the EditText: android:scrollHorizontally="false" and android:inputType="textMultiLine". The problem is by adding inputType as textMultiline, the spell checker is enabled in Android 4.x. So, by adding "textNoSuggestions" to the inputType property, the spellchecker is disabled and the problem is solved.

<TextView 
   android:id="@+id/my_text"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:scrollHorizontally="false"
   android:inputType="textMultiLine|textNoSuggestions"
   android:layout_marginTop="2dp"
   android:ellipsize="end" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!