0

I am building an Android application that will work on all screen sizes, I am using sp for the text size but there is a problem with the font size on different android screens.

The attached photo for a tablet 10 inch, can anyone help me?

screenshot:

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

// In this TesxtView i used sp instead of 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>
curious
  • 1,450
  • 5
  • 17
  • 32

4 Answers4

3

Create folder for different size and create dimen file inside that folder. (as per screen size)

values

values-small

values-normal

values-large

values-xlarge
Zezariya Nilesh
  • 390
  • 2
  • 14
1

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" />
Akshay Raiyani
  • 1,086
  • 7
  • 19
  • Please add some sample code/example to supplement your answer. Currently this is Link Only answer. See https://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers – Abdul Rauf Sep 13 '17 at 04:58
0

For different text sizes, try using

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

You have the options of small, medium and large here. I believe that this would give you more consistency but this is a very vast topic. I would refer you to go through Documentation. Helpful Link https://material.io/guidelines/style/typography.html

Aman
  • 149
  • 13
-1
  1. You must set your size of a text in SP

  2. Extract all those SPs in your application to dimen folder (simply press alt+enter combination, when hover cursor on the SP)

  3. Create different dimen folders for different screen sizes. You can do it manually or use this plugin. The trick is in next : your sp will be in dimen folder. Creating different screen folders plugin i link to autogenerates alternative values to all the dimens

kboskin
  • 133
  • 1
  • 10