Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用setText()时Android TextView中缺少空间_Android_Ascii_Textview - Fatal编程技术网

使用setText()时Android TextView中缺少空间

使用setText()时Android TextView中缺少空间,android,ascii,textview,Android,Ascii,Textview,我正在编写一个应用程序,它从ASCII时钟服务器获取时间并将其显示在屏幕上。单击按钮时,异步任务将在后台运行以获取时间。onProgressUpdate()将不断更新时间-参数s是存储ASCII时间的位置: protected void onProgressUpdate(String... s) { // I had to use a StringBuilder here because otherwise // the real

我正在编写一个应用程序,它从ASCII时钟服务器获取时间并将其显示在屏幕上。单击按钮时,异步任务将在后台运行以获取时间。onProgressUpdate()将不断更新时间-参数s是存储ASCII时间的位置:

protected void onProgressUpdate(String... s) {
                // I had to use a StringBuilder here because otherwise
                // the real ASCII art won't be printed out
                StringBuilder builder = new StringBuilder();
                for(String str : s){
                    builder.append(str);
                }
                String tmp = builder.toString();
                Log.i(TAG, tmp);
                textView.setText("Server returned time: \n" + tmp);
            }
记录的字符串看起来很好:

但屏幕上显示的输出缺少很多空间:


不确定为什么会发生这种情况,因为传递给logcat的相同字符串也在TextView中设置。

请尝试在TextView中使用单空格字体。默认的可变宽度字体不会使空格的宽度与$相同

在TextView的XML中,添加以下属性:

android:typeface="monospace"

尝试在文本视图中使用单空格字体。默认的可变宽度字体不会使空格的宽度与$相同

在TextView的XML中,添加以下属性:

android:typeface="monospace"

你的问题是它把你的内部空间减少了一半

eg-8至4

因为java字符串将每个字符视为16位的Unicode 您需要编码8位以显示相同的输出

或者试试这个

textView.setText(temp.replace(" ","  "));

尝试将空格替换为

并将其用于setText

  textView.setText(Html.fromHtml(temp));

你的问题是它把你的内部空间减少了一半

eg-8至4

因为java字符串将每个字符视为16位的Unicode 您需要编码8位以显示相同的输出

或者试试这个

textView.setText(temp.replace(" ","  "));

尝试将空格替换为

并将其用于setText

  textView.setText(Html.fromHtml(temp));
我想出来了。 setTypeface()就可以了。

我想出来了。
setTypeface()就可以了。

曾经放弃投票的人必须解释原因!!你试过使用Html.fromHtml(temp)吗?当你在不同的屏幕大小上尝试时,你会得到相同的输出吗?@Mohit是的,我在不同的屏幕大小上得到了相同的输出。@Hareshchelana我得到了。但它抹去了几乎所有的空间。曾经放弃投票的人必须解释为什么!!你试过使用Html.fromHtml(temp)吗?当你在不同的屏幕大小上尝试时,你会得到相同的输出吗?@Mohit是的,我在不同的屏幕大小上得到了相同的输出。@Hareshchelana我得到了。但它几乎抹去了所有的空间,我只是把它添加到monospace属性中,但它并没有真正改变输出。还缺地方。你确定没有吗?它做了什么,你能发布一个截图吗?它对我来说很好,我只是把它添加到monospace属性中,但它并没有真正改变输出。还缺地方。你确定没有吗?它做了什么,你能发布一个截图吗?这对我来说很好。我不允许更改服务器;但我确实尝试了fromHtml(),但没有真正起作用;但我确实尝试了fromHtml(),但没有真正起作用。