How to handle the DP with Compose, In XML-based vi...
# getting-started
p
How to handle the DP with Compose, In XML-based views, I provide multi-screen support by using the SDP library (https://github.com/intuit/sdp), but I don't know how to handle DP with Compose. Can someone help me with how to handle this?
a
That lib — and ssp — defines its dimensions in values-sw* folders. There's nothing stopping you from defining your own set of units. You can use window utilities provided by
androidx.compose.material3:material3-window-size-class
or, again, define your own. In my opinion though, if you're simply scaling up UI to fit larger screens, you're wasting the fact that you have more screen real estate to work with. Displaying the same amount of info regardless of available space feels wrong.
d
You can use something like this. If I remember correctly, intuit used 360 or similar as BASE_SCREEN_WIDTH
Copy code
inline val Int.sdp: Dp
    @Composable get() {
         val configuration = LocalConfiguration.current
         val screenWidth = configuration.screenWidthDp.toFloat()
         return screenWidth.div(BASE_SCREEN_WIDTH).times(this).dp
    }
However, I do agree with @ascii. Instead of just scaling the content, we should use the available space judiciously.