当TextView显示没有空格的长文本时文本丢失

发布于 2025-01-04 01:15:15 字数 3610 浏览 1 评论 0原文

我的 TextView 及其所有容器已将 layout_height 设置为 wrap_content。它可以很好地显示带有空格的文本(例如:英语),但对于没有任何空格的文本(例如:日语或只是一些没有空格的长文本),一些文本丢失了。

它似乎可以工作当我附加带有两个空格和一个字母的没有空格的文本时,正确无误。天哪,我不知道为什么:(

msg += "  a";

下面是我的布局。任何帮助将不胜感激!谢谢

<?xml version="1.0" encoding="UTF-8"?>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/push_header_bg" >      
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="0dp"
        android:layout_marginLeft="1dp"
        android:layout_marginBottom="0dp"
        android:src="@drawable/push_logo" />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"            
        android:gravity="center"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="40dp"
        android:text="@string/app_name"
        android:textColor="@android:color/white"
        android:textSize="22dp"
        android:textStyle="bold" />

</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/push_center_bg"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/tv_push_sub_header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/push_sub_header"
        android:textSize="20dp"        
        android:layout_marginTop="10dp"         
        android:textColor="@android:color/black"
        android:textStyle="bold" />     
        <TextView            
            android:id="@+id/tv_push"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"         
            android:textSize="20dp"             
            android:text="今日は、何事にもパワフルなエネルギーに満ちている1日。また..."            
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp"             
            android:textColor="@android:color/black" />       
</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"         
    android:gravity="center"       
    android:paddingLeft="30dp"
    android:paddingRight="30dp"
    android:background="@drawable/push_footer_bg" >
    <Button
        android:id="@+id/btn_close"
        android:layout_width="90dp"
        android:layout_height="wrap_content"
        android:background="@drawable/button_selector"
        android:text="@string/push_btn_close"
        android:textColor="@android:color/white"
        android:textStyle="bold"
        android:padding="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp" />
    <Button
        android:id="@+id/btn_open"
        android:layout_width="90dp"
        android:layout_height="wrap_content"
        android:background="@drawable/button_selector"
        android:text="@string/push_btn_open_app"
        android:textColor="@android:color/white"
        android:textStyle="bold"
        android:padding="10dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="10dp" />

</LinearLayout>

My TextView and all of its containers was set layout_height to wrap_content. It displays text with space in it (eg: English) well but with text without any space (eg: Japanese or just some long text without space in it), some text was lost.

It seems to work correctly when i append that text without space with two spaces and a letter. Omg i don't know why :(

msg += "  a";

Below is my layout. Any help will be appreciated! Thanks you

<?xml version="1.0" encoding="UTF-8"?>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/push_header_bg" >      
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="0dp"
        android:layout_marginLeft="1dp"
        android:layout_marginBottom="0dp"
        android:src="@drawable/push_logo" />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"            
        android:gravity="center"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="40dp"
        android:text="@string/app_name"
        android:textColor="@android:color/white"
        android:textSize="22dp"
        android:textStyle="bold" />

</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/push_center_bg"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/tv_push_sub_header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/push_sub_header"
        android:textSize="20dp"        
        android:layout_marginTop="10dp"         
        android:textColor="@android:color/black"
        android:textStyle="bold" />     
        <TextView            
            android:id="@+id/tv_push"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"         
            android:textSize="20dp"             
            android:text="今日は、何事にもパワフルなエネルギーに満ちている1日。また..."            
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp"             
            android:textColor="@android:color/black" />       
</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"         
    android:gravity="center"       
    android:paddingLeft="30dp"
    android:paddingRight="30dp"
    android:background="@drawable/push_footer_bg" >
    <Button
        android:id="@+id/btn_close"
        android:layout_width="90dp"
        android:layout_height="wrap_content"
        android:background="@drawable/button_selector"
        android:text="@string/push_btn_close"
        android:textColor="@android:color/white"
        android:textStyle="bold"
        android:padding="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp" />
    <Button
        android:id="@+id/btn_open"
        android:layout_width="90dp"
        android:layout_height="wrap_content"
        android:background="@drawable/button_selector"
        android:text="@string/push_btn_open_app"
        android:textColor="@android:color/white"
        android:textStyle="bold"
        android:padding="10dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="10dp" />

</LinearLayout>

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

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

发布评论

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

评论(2

当梦初醒 2025-01-11 01:15:15

尝试通过本地化来完成此操作,

  1. 在项目的 res 文件夹中创建一个文件夹 value-ja
    制作 strings.xml 并将您的日语字符串放在这里

res>values-ja>strings.xml

<string name="TextValue">今日は、何事にもパワフルなエネルギーに満ちている1日。また...</string>

在您的layout.xml 文件中使用这个“TextValue”。喜欢:

<TextView android:id="@+id/textView" android:layout_width="wrap_content"
    android:text="@string/TextValue" android:layout_height="wrap_content"
     />

Try to do this thing by localization

  1. create a folder values-ja in res folder of your project
    make strings.xml and put your Japanese string here

res>values-ja>strings.xml

<string name="TextValue">今日は、何事にもパワフルなエネルギーに満ちている1日。また...</string>

use this "TextValue" in your layout.xml file. Like:

<TextView android:id="@+id/textView" android:layout_width="wrap_content"
    android:text="@string/TextValue" android:layout_height="wrap_content"
     />
仙气飘飘 2025-01-11 01:15:15

我不知道我的输出是否正确,因为我不懂日语,,,但我使用 UTF8 形式的日语数据,它显示如下(屏幕截图如下) 在此处输入图像描述

在此我执行附加和空格。

I dont know whether my output is correct or not coz i don't know Japanese ,,, but i use Japanese data in UTF8 form and it display like this (screen shot is given bellow) enter image description here

in this i perform append and space.

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