android - 根据设备大小增加字体大小

标签 android textview

我计划在不同的设备大小上为 textview 使用不同的字体大小,以使字母清晰易读。我已经决定不为不同的设备使用不同的布局,并建立了一个通用的布局来适应所有的设备。现在唯一的问题是文本大小。

问题:

  1. 我想就如何根据设备的大小(物理大小)更改字体大小获得您的技术建议。

  2. 如何根据纵横比推导出字体大小。

  3. 使用这种方法有什么缺陷吗?

TextView 的 XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tvValue4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="I planned to use different font size for the textview on different device size so as to make the letters legible. I have already decided not to use different layouts for different devices and built a common layout to fit in all the devices. Now the only problem is on the text size."
        android:textColor="#000000"
        android:textSize="15sp" />

</LinearLayout>

提前致谢

最佳答案

是的,这种方法是有缺陷的。 Android 设备具有不同的尺寸,但它们的密度也可能非常不同。

enter image description here

您应该只遵循 Android 设计 best practices .

enter image description here

他们实际上是经过深思熟虑的。为什么要重新发明轮子?

关于android - 根据设备大小增加字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15715324/

相关文章:

android - 如何将操作栏添加到 Android Studio 中的默认 Google Maps API?

java - 如何使用 Android Sdk 在 aws S3 存储桶中创建空文件夹?

android - 绑定(bind)服务与存储库

html - 我可以获取某个 ID 中每个 <p> 和 </p> 之间的所有文本吗

java - 如何将 TextView 中的框架放入表格的形式?

Android ListView 行文本动态变化

android - 无论 drawableLeft 如何将文本居中放置在 Button 中?

安卓数据绑定(bind): visibility on include tag

android - 从 onItemClick 确定 AutoCompleteTextView

android - 如何禁用 ListView 的 ScrollView 并为包含 ListView 和其他 TextView 的整个 Activity 应用 ScrollView ?