在Android Studio中以完美的列打印 我正处于一个任务的中间,要求我在Eclipse和Android Studio中打印出一张足球联赛表。当我在eclipse中使用以下代码时,它完美地排列了所有内容,但在android中使用时会产生以下结果: public void printResults(InputStream here){ Main letsRun = new Main(here); results = letsRun.runCode(); String presentation = ""; StringBuilder bld = new StringBuilder(); String results2 = ""; presentation = "TEAM NAME Wins Draws Losses Points" + "\n"; for(Standings test : results){ String test2 = test.getTeam() +" " + test.getWins() +" " + test.getDraws()+" " + test.getLosses() +" "+test.getPoints() +"\n"; bld.append(test2); } results2 = bld.toString(); presentation += "The percentage of games predicted successfully for this season was: " + letsRun.getSuccessfullyPredicted(); Intent intent = new Intent(getBaseContext(), DisplayResults.class); intent.putExtra("KEY", presentation); intent.putExtra("results", results2); startActivity(intent); }

在Android Studio中以完美的列打印 我正处于一个任务的中间,要求我在Eclipse和Android Studio中打印出一张足球联赛表。当我在eclipse中使用以下代码时,它完美地排列了所有内容,但在android中使用时会产生以下结果: public void printResults(InputStream here){ Main letsRun = new Main(here); results = letsRun.runCode(); String presentation = ""; StringBuilder bld = new StringBuilder(); String results2 = ""; presentation = "TEAM NAME Wins Draws Losses Points" + "\n"; for(Standings test : results){ String test2 = test.getTeam() +" " + test.getWins() +" " + test.getDraws()+" " + test.getLosses() +" "+test.getPoints() +"\n"; bld.append(test2); } results2 = bld.toString(); presentation += "The percentage of games predicted successfully for this season was: " + letsRun.getSuccessfullyPredicted(); Intent intent = new Intent(getBaseContext(), DisplayResults.class); intent.putExtra("KEY", presentation); intent.putExtra("results", results2); startActivity(intent); },android,printing,Android,Printing,我尝试过使用String.format(),但这似乎对我也不起作用,我想知道有没有人能在android中让所有列完美地排列起来?ASCII艺术(包括像您这样的表格)需要单空格字体 因此,一种方法是坚持使用现有代码,但在显示输出时使用单空格字体 更好的办法包括: 使用表格布局创建实际表格 使用HTML和适当的标记(例如,,,)来创建实际的表 使用monospace(说真的,它会起作用)。。。但更严重的是。。。Android上的表(带列)非常糟糕(请记住,您必须支持多种设备大小)。。。使用一些Li


我尝试过使用String.format(),但这似乎对我也不起作用,我想知道有没有人能在android中让所有列完美地排列起来?

ASCII艺术(包括像您这样的表格)需要单空格字体

因此,一种方法是坚持使用现有代码,但在显示输出时使用单空格字体

更好的办法包括:

  • 使用
    表格布局
    创建实际表格
  • 使用HTML和适当的标记(例如,
    )来创建实际的表

使用monospace(说真的,它会起作用)。。。但更严重的是。。。Android上的表(带列)非常糟糕(请记住,您必须支持多种设备大小)。。。使用一些ListView或RecyclerView和漂亮的卡片instead@Selvin如何将文本设置为单空格?我是在android studio的文本视图框中还是在实际文件中执行?通过设置TextView@Selvin我爱你!作品完美非常感谢:)请告诉我,你只是想看看它或显示一些原型,你不会在生产中使用它。。。。这是个糟糕的主意。。。请看cw的答案,以获得更好的解决方案