Fix field centering
This commit is contained in:
parent
2d6e98cd26
commit
d982429b7f
2 changed files with 10 additions and 29 deletions
|
@ -32,10 +32,7 @@
|
|||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:drawableStart="@drawable/timer"
|
||||
android:drawableLeft="@drawable/timer"
|
||||
android:drawablePadding="8dp"
|
||||
android:drawableTint="?android:attr/textColorPrimary"
|
||||
android:gravity="center_vertical"
|
||||
android:includeFontPadding="false"
|
||||
android:minEms="2"
|
||||
|
@ -51,17 +48,17 @@
|
|||
ads:layout_constraintTop_toTopOf="@id/menu"
|
||||
tools:targetApi="m"
|
||||
tools:text="10:00"
|
||||
tools:visibility="visible" />
|
||||
tools:visibility="visible"
|
||||
ads:drawableTint="?android:attr/textColorPrimary"
|
||||
ads:drawableStartCompat="@drawable/timer"
|
||||
ads:drawableLeftCompat="@drawable/timer" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/minesCount"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:drawableStart="@drawable/mine"
|
||||
android:drawableLeft="@drawable/mine"
|
||||
android:drawablePadding="8dp"
|
||||
android:drawableTint="?android:attr/textColorPrimary"
|
||||
android:gravity="center_vertical"
|
||||
android:includeFontPadding="false"
|
||||
android:minEms="3"
|
||||
|
@ -76,7 +73,9 @@
|
|||
ads:layout_constraintTop_toTopOf="@id/menu"
|
||||
tools:targetApi="m"
|
||||
tools:text="99"
|
||||
tools:visibility="visible" />
|
||||
tools:visibility="visible"
|
||||
ads:drawableStartCompat="@drawable/mine"
|
||||
ads:drawableTint="?android:attr/textColorPrimary" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/newGame"
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package dev.lucasnlm.antimine.common.level.view
|
||||
|
||||
import android.util.TypedValue
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
|
@ -30,35 +29,18 @@ abstract class CommonLevelFragment(@LayoutRes val contentLayoutId: Int) : Fragme
|
|||
}
|
||||
|
||||
protected fun calcHorizontalPadding(boardWidth: Int): Int {
|
||||
val context = requireContext()
|
||||
val displayMetrics = context.resources.displayMetrics
|
||||
|
||||
val width = displayMetrics.widthPixels
|
||||
val width = requireView().measuredWidth
|
||||
val recyclerViewWidth = (dimensionRepository.areaSize() * boardWidth)
|
||||
val separatorsWidth = (dimensionRepository.areaSeparator() * (boardWidth - 1))
|
||||
return ((width - recyclerViewWidth - separatorsWidth) / 2).coerceAtLeast(0.0f).toInt()
|
||||
}
|
||||
|
||||
protected fun calcVerticalPadding(boardHeight: Int): Int {
|
||||
val context = requireContext()
|
||||
val displayMetrics = context.resources.displayMetrics
|
||||
|
||||
val typedValue = TypedValue()
|
||||
val actionBarHeight = if (context.theme.resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) {
|
||||
TypedValue.complexToDimensionPixelSize(typedValue.data, resources.displayMetrics)
|
||||
} else {
|
||||
0
|
||||
}
|
||||
val resourceId: Int = resources.getIdentifier("navigation_bar_height", "dimen", "android")
|
||||
val navigationHeight = if (resourceId > 0) {
|
||||
resources.getDimensionPixelSize(resourceId)
|
||||
} else 0
|
||||
|
||||
val height = displayMetrics.heightPixels
|
||||
val height = requireView().measuredHeight
|
||||
val recyclerViewHeight = (dimensionRepository.areaSize() * boardHeight)
|
||||
val separatorsHeight = (2 * dimensionRepository.areaSeparator() * (boardHeight - 1))
|
||||
|
||||
val calculatedHeight = (height - actionBarHeight - navigationHeight - recyclerViewHeight - separatorsHeight)
|
||||
val calculatedHeight = (height - recyclerViewHeight - separatorsHeight)
|
||||
|
||||
return (calculatedHeight / 2).coerceAtLeast(0.0f).toInt()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue