【问题标题】:How to set same text size in android app?如何在android应用程序中设置相同的文本大小?
【发布时间】:2015-09-21 09:31:00
【问题描述】:

我想知道如何在所有设备上使您的 MainScreen 文本大小相同(我使用的是 android studio)我有 65dp 文本,但是一旦我在具有更大屏幕的模拟器上运行它,我的文本就会小得多。

【问题讨论】:

    标签: java android xml android-studio


    【解决方案1】:

    请查看https://stackoverflow.com/a/7608270/3353195

    块引用

    沃伦信仰 编译器同时接受“dip”和“dp”,但“dp”与“sp”更一致。

    【讨论】:

      【解决方案2】:

      您可以使用屏幕的当前分辨率,文本大小将与每台设备成比例。这样你就可以使用这样的东西:

      //get your textView
      TextView text = (TextView) findViewById(R.id.titleField);
      text.setText("Your title here");
      text.setTextSize(65 * getResources().getDisplayMetrics().density);
      

      您可以对 MainScreen 中的每个 TextView 执行此操作。希望这对你有帮助:)

      附:您可以在这里找到更多针对您的案例的建议:Text size with different resolution

      【讨论】:

        【解决方案3】:

        永远不要使用“dp”来指定文本大小。始终对 textsize 使用“sp”,对其他所有内容使用“dp”。

        android:textSize="25sp"
        
        android:layout_width="50dp"
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-02-28
          • 2014-03-08
          • 1970-01-01
          • 2012-02-13
          相关资源
          最近更新 更多