Лучшая практика для макета с краем до края в режиме ландшафта API 35Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Лучшая практика для макета с краем до края в режиме ландшафта API 35

Сообщение Anonymous »

Могу ли я узнать, есть ли наилучшая практика или официальный способ обработки в API 35, в частности, в режиме ландшафта? alt = "Введите описание изображения здесь" src = "https://i.sstatic.net/xv22nzhi.png"/>

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

//
// Fragment's code.
//
private void edgeToEdge() {
final Rect topLinearLayoutInitialPadding = new Rect(
topLinearLayout.getPaddingLeft(),
topLinearLayout.getPaddingTop(),
topLinearLayout.getPaddingRight(),
topLinearLayout.getPaddingBottom()
);

final Rect scrollViewInitialPadding = new Rect(
scrollView.getPaddingLeft(),
scrollView.getPaddingTop(),
scrollView.getPaddingRight(),
scrollView.getPaddingBottom()
);

final Rect bottomFrameLayoutInitialPadding = new Rect(
bottomFrameLayout.getPaddingLeft(),
bottomFrameLayout.getPaddingTop(),
bottomFrameLayout.getPaddingRight(),
bottomFrameLayout.getPaddingBottom()
);

// 2. Apply a listener to handle window insets for all orientations
ViewCompat.setOnApplyWindowInsetsListener(this.getView(), (v, insets) -> {
// Get the insets for the system bars (status bar, navigation bar)
Insets theInsets = insets.getInsets(
WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout() | WindowInsetsCompat.Type.ime()
);

topLinearLayout.setPadding(
topLinearLayoutInitialPadding.left + theInsets.left,
topLinearLayoutInitialPadding.top + 0,
topLinearLayoutInitialPadding.right + theInsets.right,
topLinearLayoutInitialPadding.bottom + 0
);

scrollView.setPadding(
scrollViewInitialPadding.left + theInsets.left,
scrollViewInitialPadding.top + 0,
scrollViewInitialPadding.right + theInsets.right,
scrollViewInitialPadding.bottom + 0
);

bottomFrameLayout.setPadding(
bottomFrameLayoutInitialPadding.left + theInsets.left,
bottomFrameLayoutInitialPadding.top + 0,
bottomFrameLayoutInitialPadding.right + theInsets.right,
bottomFrameLayoutInitialPadding.bottom + theInsets.bottom
);

// Return the insets to allow the system to continue processing them
return insets;
});
}

//
// Activity's code
//
private void setOnApplyWindowInsetsListener() {
final Rect initialPadding = new Rect(
toolbarFrameLayout.getPaddingLeft(),
toolbarFrameLayout.getPaddingTop(),
toolbarFrameLayout.getPaddingRight(),
toolbarFrameLayout.getPaddingBottom()
);

// 2. Apply a listener to handle window insets for all orientations
ViewCompat.setOnApplyWindowInsetsListener(toolbarFrameLayout, (v, insets) -> {
// Get the insets for the system bars (status bar, navigation bar)
Insets theInsets = insets.getInsets(
WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout()
);

v.setPadding(
initialPadding.left + theInsets.left,
initialPadding.top + 0,
initialPadding.right + theInsets.right,
initialPadding.bottom + 0
);

// Return the insets to allow the system to continue processing them
return insets;
});
}
Напротив, макет приложения настройки Google в режиме ландшафта, по-видимому, использует гораздо более простой подход. Для рекомендованного или официального способа достижения режима до края в режиме ландшафта API 35?

Подробнее здесь: https://stackoverflow.com/questions/797 ... scape-mode
Ответить

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

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

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

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

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