i am currently working on a android studio Kotlin project where i faced some problems about the scaling. i have tried my app on different devices (particularly s21 ultra and s23). on the s21 it looks perfect but on the s23 everything has the same size as on the s21 but for example variables that are inside the layouts either gets crushed or messed up. my xml has constraintlayout on top viewpager at the center and another constraintlayout at the bottom. inside the viewpager i have a recyclerview which is filled with materialcardviews as an item. i don't have problems with the constraintlayouts its just that variables(textview mostly, imagebutton etc.) inside the materialcardview gets messed up (i use sp for text size). i think that it is correct to not have everything the same size on different screen sizes, or maybe you have to have it like that? I'll take any advice.
i have tried to force the phone to run the app on fixed minimum width (the one that is inside the developer options) but i dont think its a good option.
^^^
class MainActivity : AppCompatActivity(), QuantityListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val changeddp = 478
overrideDensity(changeddp)
//^^^^before setting the layout(in my case test2), change the width.
setContentView(R.layout.test2)
}
}
private fun overrideDensity(changeddp: Int) {
val resources = resources
val configuration = resources.configuration
val screenwidthPx = resources.displayMetrics.widthPixels
val newDensity = screenwidthPx.toFloat() / changeddp
configuration.densityDpi = (newDensity * 160).toInt()
resources.updateConfiguration(configuration, resources.displayMetrics)
}
Thanks for your time.
i am currently working on a android studio Kotlin project where i faced some problems about the scaling. i have tried my app on different devices (particularly s21 ultra and s23). on the s21 it looks perfect but on the s23 everything has the same size as on the s21 but for example variables that are inside the layouts either gets crushed or messed up. my xml has constraintlayout on top viewpager at the center and another constraintlayout at the bottom. inside the viewpager i have a recyclerview which is filled with materialcardviews as an item. i don't have problems with the constraintlayouts its just that variables(textview mostly, imagebutton etc.) inside the materialcardview gets messed up (i use sp for text size). i think that it is correct to not have everything the same size on different screen sizes, or maybe you have to have it like that? I'll take any advice.
i have tried to force the phone to run the app on fixed minimum width (the one that is inside the developer options) but i dont think its a good option.
^^^
class MainActivity : AppCompatActivity(), QuantityListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val changeddp = 478
overrideDensity(changeddp)
//^^^^before setting the layout(in my case test2), change the width.
setContentView(R.layout.test2)
}
}
private fun overrideDensity(changeddp: Int) {
val resources = resources
val configuration = resources.configuration
val screenwidthPx = resources.displayMetrics.widthPixels
val newDensity = screenwidthPx.toFloat() / changeddp
configuration.densityDpi = (newDensity * 160).toInt()
resources.updateConfiguration(configuration, resources.displayMetrics)
}
Thanks for your time.
Share Improve this question edited Mar 9 at 17:36 luka lutidze asked Mar 9 at 17:23 luka lutidzeluka lutidze 315 bronze badges 1- 2 Please edit the question to provide a minimal reproducible example that demonstrates the problem. – tyg Commented Mar 9 at 17:33
2 Answers
Reset to default 0Don't do any of that. Let your app handle user's configuration.
the question key is different screen ratio.
In the Point,you should create different resource by didderent ratio or width.
type | s21 | s23 |
---|---|---|
ratio | 20:9 | 19.5:9 |
px | 3200 x 1440 | 3088 x 1440 |
May use 12dp in s21 and use 11dp in s23 can reslove the question.
But this is not a good answer,because s21 s23 only few diffent.if user change text size in system setting,your layout still have the question.
your layout design may very 'fit', so that can't compatible few disfferent.
you should allow text warp(can allow 2 or more line),and save space, Or use ellipsize
show '...'