1

How to fix default display size and font size in app prevent user change system setting lead to app layout out of shape?

enter image description here

enter image description here

Squall Huang
  • 647
  • 9
  • 20
  • Why do you want to disregard user settings and make the app inaccessible to people that struggle to see sharply, or struggle with small touch targets? – Louis CAD Sep 23 '21 at 20:36

5 Answers5

0

If you use the dp (like 20dp) instead of sp (like 20sp), the text will not be scaled based on the user choice of the font size. This will simplify the UI design for you, but users make the font big for a reason: they cannot see the smaller one. So if you choose to ignore the user's settings, the user may choose to ignore your app.

Rediska
  • 1,392
  • 10
  • 14
  • I use sp for my app textview. I solved font size scale with code but can't solve display size scale lead to crop my layout. When Display size scale larger, my layout will be Cropped. – Squall Huang Sep 23 '21 at 06:44
0

Use the implementation com.intuit.sdp:sdp-android:1.0.6. It will resize according to the screen size.

ouflak
  • 2,458
  • 10
  • 44
  • 49
amol
  • 31
  • 9
0

Make sure you have used sp in the textSize attribute in your layout XML file. Text size in the sp unit can adjust itself according to android system settings.

For e.g-

..
android:textSize="14sp"
..

Also, you can check out this reference- https://stackoverflow.com/a/2025541/10632119

There are some plugins and library are available for Android Studio i.c.- "com.intuit.sdp:sdp-android", Dimenify, which will generate multiple dimems.xml files for our project according to screen density.

0

There are below things that you have to do,

  1. Use the SP for textSize with appropriate dimension values, (or use the SDP library)
  2. Use the chat box image as scalable vector image.
  • When Display size scale larger, my layout will be Cropped. – Squall Huang Sep 23 '21 at 06:41
  • Can you post the cropped layout screenshot? What is the height and width of layout, did you provided it hardcoded? It will be great if you can post your layout/xml file so i can be more precise. – Sanket Shah Sep 23 '21 at 07:07
  • I had added emulator photo and xml photo now. – Squall Huang Sep 23 '21 at 07:21
  • Okay, i would suggest to add nested scroll view on top of the viewgroup. As your screen contains the dynamic size of text data, it will required to be scrolled vertically. – Sanket Shah Sep 23 '21 at 07:26
0

Though below codes can prevent font size scale(with some deprecated methods), but can't prevent display size scale.

override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)

            adjustFontScale(resources.configuration)
}

private fun adjustFontScale(configuration: Configuration?) {
        configuration?.let {
            it.fontScale = 1.0F
            val metrics: DisplayMetrics = resources.displayMetrics
            val wm: WindowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
            wm.defaultDisplay.getMetrics(metrics)
            metrics.scaledDensity = configuration.fontScale * metrics.density

            baseContext.applicationContext.createConfigurationContext(it)
            baseContext.resources.displayMetrics.setTo(metrics)

        }
    }
Squall Huang
  • 647
  • 9
  • 20