我计划在不同的设备大小上为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>
Run Code Online (Sandbox Code Playgroud)
提前致谢
Mur*_*san 21
试试这个,在你的xml中添加这个属性.它会根据屏幕尺寸调整文本大小.
style="@android:style/TextAppearance.DeviceDefault.Medium"
Run Code Online (Sandbox Code Playgroud)
对于字体大小,请使用缩放像素(sp).Android会根据设备密度相应地缩放字体大小.以上帖子有更好的解释和推理.
Android 为此内置了工具 - dp 和 sp。dp 是设备像素。它基本上是 1dp=1/160 英寸。这允许您指定实际大小的字体高度。Sp 是缩放像素。此大小根据默认字体大小进行缩放,因此用户可以放大其系统字体,并且您的应用程序将匹配它。对于有视力问题、需要大文本的人来说非常方便,同时又不占用其他人的屏幕空间。
您可能应该使用其中之一。