【问题标题】:Printing in perfect Columns in Android Studio在 Android Studio 中打印完美的列
【发布时间】:2017-03-16 14:19:53
【问题描述】:

我正在执行一项任务,该任务要求我在 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);
} 

ResultsProducedByAndroid

我尝试过使用 String.format() 但这似乎也不适合我,我想知道有没有人有办法让所有列在 android 中完美排列?

【问题讨论】:

  • 使用等宽(真的会起作用)......但更严重的是......表格(带列)在Android上太糟糕了(记住你必须支持多种设备的尺寸)......使用一些带有漂亮卡片的 ListView 或 RecyclerView
  • @Selvin 如何将我的文本设置为等宽字体?我是在 android studio 的 TextView 框中执行此操作还是对实际文件执行此操作?
  • 通过设置TextView的字体
  • @Selvin 我爱你!非常感谢:)
  • 请告诉我,您只是想检查一下或展示一些原型,您不会在生产中使用它......这是一个糟糕的主意......请查看 cw 的答案以获得更好的解决方案

标签: android printing


【解决方案1】:

ASCII 艺术——包括像你这样的表格——需要等宽字体。

因此,一种方法是坚持使用现有代码,但在显示该输出时使用等宽字体。

更好的方法包括:

  • 使用TableLayout 创建实际表
  • 使用 HTML 和适当的标签(例如,<table><tr><td>)来创建一个实际的表格

【讨论】:

    猜你喜欢
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多