2017-09-13 300 views
0

我正在構建可在所有屏幕尺寸上工作的Android應用程序,我將sp用於文本大小,但在不同的android屏幕上字體大小存在問題。無法處理所有屏幕尺寸的字體大小

10英寸平板電腦附帶的照片,任何人都可以幫助我嗎?

截圖:

screenshot

<?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> 

回答

1

使用這個庫爲集文字大小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" /> 
+0

請添加一些示例代碼/例如,以補充你的答案。目前這是Link Only的答案。見https://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers –

0

對於不同文本的大小,請嘗試使用

android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large" 
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small" 
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" 

你有小型,中型和大型這裏的選項。我相信這會給你更多的一致性,但這是一個非常廣泛的話題。我會引用你閱讀文檔。 有用的鏈接https://material.io/guidelines/style/typography.html

0
  1. 您必須設置文本的大小SP

  2. 提取所有的SP在應用程序中捫文件夾(只需按下Alt + Enter組合,懸停光標時,對SP )

  3. 爲不同的屏幕尺寸創建不同的尺寸文件夾。您可以手動或使用this plugin。訣竅在下:你的SP將在維度文件夾中。創建不同的屏幕文件夾插件我鏈接到自動生成替代值到所有維度

2

創建不同大小的文件夾並在該文件夾內創建dimen文件。 (根據屏幕大小)

values 

values-small 

values-normal 

values-large 

values-xlarge