如何在Android应用程序中设置相同的文字大小?

时间:2015-07-03 13:53:32

标签: java android xml android-studio

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

3 个答案:

答案 0 :(得分:1)

永远不要使用" dp"用于指定文本化。始终使用" sp"用于textize和" dp"其他一切。

android:textSize="25sp"

android:layout_width="50dp"

答案 1 :(得分:0)

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

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

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

P.S。您可以在此处找到有关您案例的更多建议:Text size with different resolution

答案 2 :(得分:0)

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

  

块引用

WarrenFaith 编译器接受" dip"和" dp",虽然" dp"更符合" sp"。