优化导航栏位置

pull/1395/head
gedoor 3 years ago
parent 99c0db589c
commit 585415c541
  1. 6
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  3. 22
      app/src/main/java/io/legado/app/utils/ActivityExtensions.kt

@ -157,17 +157,17 @@ abstract class ReadBookBaseActivity :
0
}
when (navigationBarPos) {
0 -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply {
POS.BOTTOM -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply {
height = navigationBarHeight
width = MATCH_PARENT
gravity = Gravity.BOTTOM
}
1 -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply {
POS.LEFT -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply {
height = MATCH_PARENT
width = navigationBarHeight
gravity = Gravity.LEFT
}
2 -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply {
POS.RIGHT -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply {
height = MATCH_PARENT
width = navigationBarHeight
gravity = Gravity.RIGHT

@ -316,9 +316,9 @@ class ReadMenu @JvmOverloads constructor(
vwMenuBg.setOnClickListener { runMenuOut() }
root.padding = 0
when (activity?.navigationBarPos) {
0 -> root.bottomPadding = navigationBarHeight
1 -> root.leftPadding = navigationBarHeight
2 -> root.rightPadding = navigationBarHeight
POS.BOTTOM -> root.bottomPadding = navigationBarHeight
POS.LEFT -> root.leftPadding = navigationBarHeight
POS.RIGHT -> root.rightPadding = navigationBarHeight
}
}
if (!LocalConfig.readMenuHelpVersionIsLast) {

@ -77,24 +77,22 @@ val Activity.navigationBarHeight: Int
* 1 left
* 2 right
*/
val Activity.navigationBarPos: Int
val Activity.navigationBarPos: POS
get() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
var pos = 0
val display: Display = windowManager.defaultDisplay
val rotate: Int = display.rotation
val height: Int = display.height
val width: Int = display.width
pos = if (width > height) {
return if (width > height) {
if (rotate == Surface.ROTATION_270) {
1 //left
POS.LEFT
} else {
2 //right
POS.RIGHT
}
} else {
0 //bottom
POS.BOTTOM
}
return pos
} else {
val display: Display = windowManager.defaultDisplay
val metricsReal = DisplayMetrics()
@ -110,9 +108,13 @@ val Activity.navigationBarPos: Int
val realH = metricsReal.heightPixels
return if (currW != realW && currH == realH) {
2
POS.RIGHT
} else {
0
POS.BOTTOM
}
}
}
}
enum class POS {
BOTTOM, LEFT, RIGHT
}
Loading…
Cancel
Save