文本视图不会破坏文本[英] TextView won't break text

本文是小编为大家收集整理的关于文本视图不会破坏文本的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我在ICC之前没有破坏线条的问题.在ICS(我相信蜂窝的工作也是如此,但我还没有尝试过它)TextView内部的文字很好,但在姜饼和低于文本中只是继续一行.任何想法如何解决这个问题?

我正在使用视角ager,这是每个屏幕的布局.我正在使用自定义TextView只是为了添加自定义字体,希望不是问题.

pager_item.xml:`

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="20dp" >

    <com.ursus.absolution.startme.MyTextView
        android:id="@+id/message_textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/quotes_background"
        android:gravity="center"
        android:textColor="#585858"
        android:textSize="25dp" />

    <com.ursus.absolution.startme.MyTextView
        android:id="@+id/author_textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="#585858"
        android:textSize="20dp" />

</LinearLayout>`

In ICS
_____________
|           |
|           |
| "This is  |
|  my cool  |
|   text"   |
|           |
|___________|

In gingerbread and below
_____________
|           |
|           |
| "This is my cool text"
|           |
|           |
|           |
|___________|

抱歉im新的我不能发布图片.提前致谢,希望你们得到它.

/////////////////////////////////shion>

好的家伙,这非常有趣..我尝试了所有的建议,但既没有工作,所以我开始了一个新的空白项目,只需长长的字符串,它刚刚绑定到布局.

所以,我不知道这可能是怎么可能的,但它是它的自定义主题来样式的动作栏这样做,当我在清单中发表评论它它的工作就是很好的,然而,系统holo主题似乎正在做这件事

androidmanifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ursus.absolution.startme"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />

<application
    android:icon="@drawable/iconn"
    android:label="@string/app_name"
    android:theme="@style/Theme.myStyle" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
    </activity>
    <activity
        android:name=".SplashScreenActivity"
        android:label="@string/title_activity_main"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

styles.xml

<resources>

<style name="Theme.myStyle" parent="@android:style/Theme.Holo">
    <item name="android:actionBarStyle">@style/mycoolstyle_transparent_ActionBar</item>
</style>

<style name="mycoolstyle_transparent_ActionBar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">@drawable/transparent_actionbar</item>
</style>

......所以当我添加Android:主题="@样式/主题"中的表单中的TextViews misbehave 但是当我添加Android:主题="@ android:style/theme.holo"时,因为我通常会强制Holo主题,它误导Aswell

奇怪.

推荐答案

这个问题以各种形式这里 href ="https://stackoverflow.com/questions/11136145/android-textview-text-not-wrapping-within-relativelayout-on-version-3-3">这里.许多问题报告了以前的工作布局在更新IC/holo主题时被破坏.

我能够轻松再现它,这是一行XML的问题:@android:style/Theme.Holo

围绕它的最简单方法是介绍了一个版本的值文件夹,让Android选择正确的文件夹.换句话说,您将拥有2 styles.xml:

  • 内部values-v11文件夹,您应该将您指定的文件(带parent="@android:style/Theme.Holo")
  • 内部旧values文件夹将放置'plain'一个,使用parent="android:Theme.Black.NoTitleBar".

您的清单应保持不变,Android将根据其版本选择正确的XML.解决方案可能不是最优雅的,但至少您不会弄乱Android:MaxLines,Android:宽度等:宽度

其他推荐答案

除了亮光答案之外,我必须将相应的参数设置为textview:

                android:ellipsize="none"
                android:maxLines="20"
                android:scrollHorizontally="false"
                android:singleLine="false" 

示例:

           <TextView                  
                android:textColor="@color/white"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="none"
                android:maxLines="20"
                android:scrollHorizontally="false"
                android:singleLine="false"
                android:text="@string/my_text" />

本文地址:https://www.itbaoku.cn/post/102321.html

问题描述

I am having trouble with textView not breaking line before ICS. In ICS (i belive honeycomb works as well but i havent tried it tho) the text inside textView breaks nicely but in gingerbread and below text just keeps going in one line. Any ideas how to fix this?

I am using a viewpager and this is the layout for each screen. I am using custom textView just to add custom font, hope thats not the problem.

pager_item.xml:`

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="20dp" >

    <com.ursus.absolution.startme.MyTextView
        android:id="@+id/message_textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/quotes_background"
        android:gravity="center"
        android:textColor="#585858"
        android:textSize="25dp" />

    <com.ursus.absolution.startme.MyTextView
        android:id="@+id/author_textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="#585858"
        android:textSize="20dp" />

</LinearLayout>`

In ICS
_____________
|           |
|           |
| "This is  |
|  my cool  |
|   text"   |
|           |
|___________|

In gingerbread and below
_____________
|           |
|           |
| "This is my cool text"
|           |
|           |
|           |
|___________|

Sorry im new i cant post pictures. Thanks in advance, hope you guys get it.

///////UPDATE///////////////

Okay guys, this is very interesting.. i tried all your suggestions however neither has worked, so i started a new blank project and just put a textview into layout with really long string and it wrapped just fine.

So, i dont know how is this possible, but its the custom theme to style the actionbar doing this, when i comment it out in the manifest it works just fine, however the system holo theme seems doing this aswell

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ursus.absolution.startme"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />

<application
    android:icon="@drawable/iconn"
    android:label="@string/app_name"
    android:theme="@style/Theme.myStyle" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
    </activity>
    <activity
        android:name=".SplashScreenActivity"
        android:label="@string/title_activity_main"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

styles.xml

<resources>

<style name="Theme.myStyle" parent="@android:style/Theme.Holo">
    <item name="android:actionBarStyle">@style/mycoolstyle_transparent_ActionBar</item>
</style>

<style name="mycoolstyle_transparent_ActionBar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">@drawable/transparent_actionbar</item>
</style>

...so when I add android:theme="@style/Theme.myStyle" in the manifest the textviews misbehave however when i add android:theme="@android:style/Theme.Holo" instead, as i normally would to force holo theme, it missbehave aswell

weird.

推荐答案

This issue is reported in various forms, here and here for example. Many of the issues reports a previous working layout that gets broken when updating to ICS/holo theme.

I was able to reproduce it easily, it's a matter of a line of xml: @android:style/Theme.Holo

The easiest way to go around it is to introduce a versioned values folder, to let Android pick the right one. In other words You'll have 2 styles.xml:

  • inside values-v11 folder you should put the one you specified (with parent="@android:style/Theme.Holo")
  • inside old values folder you'll put the 'plain' one, with parent="android:Theme.Black.NoTitleBar".

Your manifest should remain unchanged, and Android will pick the right xml based on its version. The solution may not be the most elegant, but at least you won't mess with android:maxlines, android:width and so on

其他推荐答案

In addition to Shine answer I had to set corresponding parameters to the TextView:

                android:ellipsize="none"
                android:maxLines="20"
                android:scrollHorizontally="false"
                android:singleLine="false" 

Example:

           <TextView                  
                android:textColor="@color/white"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="none"
                android:maxLines="20"
                android:scrollHorizontally="false"
                android:singleLine="false"
                android:text="@string/my_text" />