在 Android 3.1 上调整 TextView 大小不会缩小其高度

发布于 2024-11-28 22:13:38 字数 1089 浏览 2 评论 0原文

我有一个可以动态调整大小的 TextView(我使用 setTextSize())。它在 Android 2.2 上正确扩展和收缩其边界。但在Android 3.1上,当文本变小时,区域的高度不会缩小。

这是演示这一点的短视频

布局只是简单的垂直 LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dip">
... 
<TextView 
    android:id="@+id/track_number" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    style="@style/tcTrackNo" 
    android:padding="5dp" />
    ...


<style name="tcTrackNo" parent="@android:style/TextAppearance.Small">
    <item name="android:textColor">@color/track_number</item>
</style>

那么,应该做些什么额外的事情才能使 TextView 根据 Honeycomb 上的字体大小相应地降低其高度呢?

附言。同样,在 Android 2.2 上,文本区域会折叠到最小高度,没有任何问题。 视频的工作原理

I have a TextView which can be resized dinamically (I use setTextSize()). It correctly expands and shrinks its bounds on Android 2.2. But on Android 3.1, when the text become smaller, the height of area is not shrink.

Here is the short video that demonstrates that.

The layout is just simple vertical LinearLayout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dip">
... 
<TextView 
    android:id="@+id/track_number" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    style="@style/tcTrackNo" 
    android:padding="5dp" />
    ...


<style name="tcTrackNo" parent="@android:style/TextAppearance.Small">
    <item name="android:textColor">@color/track_number</item>
</style>

So, what extra should be done to make the TextView reduce its height accordingly to its font size on Honeycomb?

PS. Again, on Android 2.2 the text area collapses until the smallest height without any issue. The video how it's intended to work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北城孤痞 2024-12-05 22:13:38

可能有点晚了

由于错误http://code.google, 。 com/p/android/issues/detail?id=17343

http://code.google.com/p/android/issues/detail?id=22493

但是有一种解决方法,可以在文本末尾附加一个非宽度字符。

任何这些工作

final String DOUBLE_BYTE_SPACE = "\u3000";
final String DOUBLE_BYTE_WORDJOINER = "\u2060";
final String ZERO_WIDTH_SPACE = "\u200b";
textview.append(ZERO_WIDTH_SPACE);              

Might be a bit late it's from a bug

http://code.google.com/p/android/issues/detail?id=17343

http://code.google.com/p/android/issues/detail?id=22493

But there is a workaround by appending a non width character at the end of your text.

Any of these work

final String DOUBLE_BYTE_SPACE = "\u3000";
final String DOUBLE_BYTE_WORDJOINER = "\u2060";
final String ZERO_WIDTH_SPACE = "\u200b";
textview.append(ZERO_WIDTH_SPACE);              
一个人练习一个人 2024-12-05 22:13:38

我知道这是一个旧线程。

但上面列出的所有这些字符对我来说都不能正常工作,我在 5.0.1 中遇到了这个问题,解决方法是将 textview 重力设置为垂直中心。

希望这对任何人都有帮助:)

i know this is an old thread.

but all these characters listed above did not worked properly with me, i faced this issue with 5.0.1 and the fix was to set the textview gravity to center vertical.

hope this help anyone :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文