Как получить правильный параметр дроби для fillMaxHeight(...) и fillMaxWidth(...) в Compose, если начальное значение парAndroid

Форум для тех, кто программирует под Android
Ответить
Гость
 Как получить правильный параметр дроби для fillMaxHeight(...) и fillMaxWidth(...) в Compose, если начальное значение пар

Сообщение Гость »


As I'm progressing with my latest personal project in kotlin, Android Studio, I've recently realised that I have to make my components scale uniformly on every type of screen irrespective of screen's resolution or dpi (density per inch). The problem is, till now, for all buttons, text fields, boxes, columns etc., I've set the height and width in dp (density-independent pixels). As a consequence, the physical size of the respective components is the same on each type of screen which leads to rendering problems. What I want is the widths and heights of all the components be proportionally the same on each type of screen. From what I found on the Internet I understand that the fastest way to make the transition to what I want is to use the functions fillMaxWeight() and fillMaxWidth() applied to the modifiers with the parameter "fraction".
Thus my question is, how do I get that subunitary value if I have the current_value in dp and the screen resolution of the base case phone I simulated on in the emulator? Is it just a ratio like: currentHeight/screenHeight or currentWidth/screenWidth? And how do I get the screenHeight and screenWidth of the screen? Regarding the last question, I've already read this post:
geting the screen's width and height
What I want to ask more is if the first answer is entirely correct, regarding the case of changing the orientation of the screen? Does it still give the correct values for the screen's width and height? I attach the code snippet of the answer below.

Код: Выделить всё

@Composable
fun PostView() {
val configuration = LocalConfiguration.current

val screenHeight = configuration.screenHeightDp.dp
val screenWidth = configuration.screenWidthDp.dp

...

}
Thanks a lot in advance.


Источник: https://stackoverflow.com/questions/781 ... illmaxwidt
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»