【问题标题】:TextView won't break textTextView 不会破坏文本
【发布时间】:2012-07-20 16:19:22
【问题描述】:

我遇到了 textView 在 ICS 之前没有换行的问题。在 ICS 中(我相信蜂窝也可以,但我还没有尝试过),textView 中的文本很好地中断,但在姜饼中,下面的文本一直在一行中。任何想法如何解决这个问题?

我正在使用 viewpager,这是每个屏幕的布局。我使用自定义 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"
|           |
|           |
|           |
|___________|

对不起,我是新人,我不能发布图片。提前感谢,希望你们能得到它。

//////更新/////////////

好的,伙计们,这很有趣..我尝试了你所有的建议,但都没有奏效,所以我开始了一个新的空白项目,只是将一个 textview 放入布局中,字符串很长,它包裹得很好。

所以,我不知道这怎么可能,但它是自定义主题来设置动作栏的样式

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:theme="@style/Theme.myStyle" 时,textviews 行为异常 但是当我添加 android:theme="@android:style/Theme.Holo" 时,就像我通常会强制使用全息主题一样,它也表现不佳

很奇怪。

【问题讨论】:

  • 尝试将android:singleLine="false 添加到您的TextViews。 false 应该是默认值,但可能会在您的应用中覆盖它。
  • 常规 TextView 会自动换行,所以我认为问题出在您的自定义 TextView 上。如果您只想更改字体,请使用android:typeface="",如discussed here。如果您仍然需要帮助,请发布您的 MyTextView 课程,以便我们了解发生了什么。
  • 尝试用 FrameLayout 包装您的 LinearLayout。我认为它应该工作。 Incase,您认为自定义 TextView 有问题,请查看我的教程shubhayu.com/android/custom-control-extending-existing-views
  • ...在 froyo 上确实是由自定义字体引起的,但在姜饼上并非如此。

标签: android textview android-4.0-ice-cream-sandwich line-breaks android-2.3-gingerbread


【解决方案1】:

此问题以多种形式报告,例如herehere。许多问题报告了以前的工作布局,在更新到 ICS/holo 主题时会损坏。

我能够轻松复制它,只需一行 xml:@android:style/Theme.Holo

解决这个问题的最简单方法是引入一个版本化的值文件夹,让 Android 选择正确的文件夹。换句话说,您将拥有 2 个 styles.xml:

  • values-v11 文件夹中,您应该放置您指定的文件夹(使用parent="@android:style/Theme.Holo"
  • 在旧的values 文件夹中,您将使用parent="android:Theme.Black.NoTitleBar" 放置“普通”文件夹。

您的清单应保持不变,Android 将根据其版本选择正确的 xml。解决方案可能不是最优雅的,但至少你不会乱用 android:maxlines、android:width 等

【讨论】:

  • 天啊,非常感谢您!我有 2 个相同的应用程序,1 个免费带广告,1 个付费。 TextView 在免费版中正确显示,但在付费版中显示不正确。原来我在付费的清单中有android:theme="@android:style/Theme.Holo",但不是免费的……一旦我删除了它,它就起作用了!
【解决方案2】:

除了Shine回答我还得给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" />

【讨论】:

    猜你喜欢
    • 2015-01-07
    • 1970-01-01
    • 1970-01-01
    • 2022-10-07
    • 2015-07-02
    • 2013-11-10
    • 2012-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多