无法处理所有屏幕尺寸的字体大小
Can not handle font size in all screen size
我正在构建一个适用于所有屏幕尺寸的 Android 应用程序,我使用 sp 作为文本大小,但在不同的 android 屏幕上字体大小存在问题。
附上一张10寸平板电脑的照片,谁能帮帮我?
截图:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
// 在这个 TesxtView 中,我使用 sp 而不是 dp。
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/_6sdp"
android:layout_marginEnd="@dimen/_6sdp"
android:layout_marginLeft="@dimen/_6sdp"
android:layout_marginRight="@dimen/_6sdp"
android:layout_marginStart="@dimen/_6sdp"
android:layout_marginTop="@dimen/_110sdp"
android:text="Username"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="@+id/rectangle_login"
app:layout_constraintLeft_toLeftOf="@+id/rectangle_login"
app:layout_constraintRight_toRightOf="@+id/rectangle_login"
app:layout_constraintStart_toStartOf="@+id/rectangle_login"
app:layout_constraintTop_toTopOf="@+id/rectangle_login" />
</android.support.constraint.ConstraintLayout>
对于不同的文字大小,请尝试使用
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
这里有小号、中号和大号可供选择。我相信这会给你带来更多的一致性,但这是一个非常广泛的话题。我建议您阅读文档。
有帮助 Link https://material.io/guidelines/style/typography.html
您必须在 SP 中设置文本大小
将应用程序中的所有这些 SP 提取到 dimen 文件夹(当将光标悬停在 SP 上时,只需按 alt+enter 组合)
为不同的屏幕尺寸创建不同的 dimen 文件夹。您可以手动执行或使用 this plugin。接下来就是诀窍:您的 sp 将位于 dimen 文件夹中。创建不同的屏幕文件夹插件 i link 以自动生成所有维度的替代值
创建不同大小的文件夹并在该文件夹中创建 dimen 文件。 (根据屏幕尺寸)
values
values-small
values-normal
values-large
values-xlarge
Use this library for set text size in sp
https://github.com/intuit/ssp
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action_cancel"
android:textColor="@color/purple_light"
android:textSize="@dimen/_12ssp"
app:font="@{`hnc_roman`}"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/text_view_cancel"
android:onClick="@{v -> viewModel.onCancelClick(v)}"
tools:ignore="MissingConstraints" />
我正在构建一个适用于所有屏幕尺寸的 Android 应用程序,我使用 sp 作为文本大小,但在不同的 android 屏幕上字体大小存在问题。
附上一张10寸平板电脑的照片,谁能帮帮我?
截图:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
// 在这个 TesxtView 中,我使用 sp 而不是 dp。
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/_6sdp"
android:layout_marginEnd="@dimen/_6sdp"
android:layout_marginLeft="@dimen/_6sdp"
android:layout_marginRight="@dimen/_6sdp"
android:layout_marginStart="@dimen/_6sdp"
android:layout_marginTop="@dimen/_110sdp"
android:text="Username"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="@+id/rectangle_login"
app:layout_constraintLeft_toLeftOf="@+id/rectangle_login"
app:layout_constraintRight_toRightOf="@+id/rectangle_login"
app:layout_constraintStart_toStartOf="@+id/rectangle_login"
app:layout_constraintTop_toTopOf="@+id/rectangle_login" />
</android.support.constraint.ConstraintLayout>
对于不同的文字大小,请尝试使用
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
这里有小号、中号和大号可供选择。我相信这会给你带来更多的一致性,但这是一个非常广泛的话题。我建议您阅读文档。 有帮助 Link https://material.io/guidelines/style/typography.html
您必须在 SP 中设置文本大小
将应用程序中的所有这些 SP 提取到 dimen 文件夹(当将光标悬停在 SP 上时,只需按 alt+enter 组合)
为不同的屏幕尺寸创建不同的 dimen 文件夹。您可以手动执行或使用 this plugin。接下来就是诀窍:您的 sp 将位于 dimen 文件夹中。创建不同的屏幕文件夹插件 i link 以自动生成所有维度的替代值
创建不同大小的文件夹并在该文件夹中创建 dimen 文件。 (根据屏幕尺寸)
values
values-small
values-normal
values-large
values-xlarge
Use this library for set text size in sp https://github.com/intuit/ssp
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action_cancel"
android:textColor="@color/purple_light"
android:textSize="@dimen/_12ssp"
app:font="@{`hnc_roman`}"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/text_view_cancel"
android:onClick="@{v -> viewModel.onCancelClick(v)}"
tools:ignore="MissingConstraints" />