TextView中不会打破文TextView

2023-09-06 05:18:45 作者:沉淀*

我有ICS之前的TextView不破线的麻烦。在ICS(我相信的蜂窝工作很好,但我还没有尝试过寿)内的TextView的文字很好地休息,但只是不断朝着一个行姜饼及以下的文字。任何想法如何解决这一问题?

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?

我使用的是viewpager,这是每个屏幕的布局。我使用自定义的TextView只添加自定义字体,希望那不是问题。

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

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

好了家伙,这是非常有趣的。我尝试了所有的建议,但是他们都没有工作,所以我就开始一个新的空白项目,只是把一个TextView到布局很长的字符串,并将其包装就好了。

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中

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

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胡作非为主题=@风格/ Theme.myStyle的然而,当我加入的android:主题=@安卓风格/ Theme.Holo,而不是,因为我通常会迫使全息主题,它missbehave藏汉的

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

奇怪。

推荐答案

这个问题报道形式多样,的这里和here例如。许多问题的报告一previous工作的布局,被分解的升级到ICS /全息主题时,

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.

我能够轻松地重现出来,这是一个一行XML的问题: @android:款式/ Theme.Holo

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

去解决它最简单的方法就是为推出一个版本值的文件夹,让Android的选择是正确的。换句话说,你将有2 styles.xml:

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:

值-V11 文件夹,你应该把你指定的(与父=一个@安卓风格/ Theme.Holo) 里面的老文件夹,你会提出了'纯'之一,父=机器人:Theme.Black.NoTitleBar。 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".

您的清单应保持不变,而Android将选择它的版本正确的XML。该解决方案可能不是最优雅的,但至少你不会惹的android:maxlines的,安卓宽度等

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