style: Convert margin values to density-independent pixels in EqualizerFragment

This commit is contained in:
Jaime García 2025-09-08 22:06:26 +02:00
parent 06066f1f66
commit 2bf39d846e
No known key found for this signature in database
GPG key ID: BC4E5F71A71BDA5B

View file

@ -134,8 +134,9 @@ class EqualizerFragment : Fragment() {
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT LinearLayout.LayoutParams.WRAP_CONTENT
).apply { ).apply {
topMargin = 24 val topBottomMarginDp = 16
bottomMargin = 24 topMargin = topBottomMarginDp.dpToPx(context)
bottomMargin = topBottomMarginDp.dpToPx(context)
} }
setPadding(0, 8, 0, 8) setPadding(0, 8, 0, 8)
} }
@ -150,7 +151,8 @@ class EqualizerFragment : Fragment() {
} else { } else {
"$freq Hz" "$freq Hz"
} }
width = 120 gravity = Gravity.START
layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 2f)
} }
row.addView(freqLabel) row.addView(freqLabel)
@ -158,14 +160,14 @@ class EqualizerFragment : Fragment() {
val dbLabel = TextView(requireContext(), null, 0, R.style.LabelSmall).apply { val dbLabel = TextView(requireContext(), null, 0, R.style.LabelSmall).apply {
text = "${(initialLevel.toInt() / 100)} dB" text = "${(initialLevel.toInt() / 100)} dB"
setPadding(12, 0, 0, 0) setPadding(12, 0, 0, 0)
width = 120
gravity = Gravity.END gravity = Gravity.END
layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 2f)
} }
val seekBar = SeekBar(requireContext()).apply { val seekBar = SeekBar(requireContext()).apply {
max = maxLevel - minLevel max = maxLevel - minLevel
progress = initialLevel.toInt() - minLevel progress = initialLevel.toInt() - minLevel
layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f) layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 6f)
setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
val thisLevel = (progress + minLevel).toShort() val thisLevel = (progress + minLevel).toShort()
@ -221,3 +223,6 @@ class EqualizerFragment : Fragment() {
} }
} }
} }
private fun Int.dpToPx(context: Context): Int =
(this * context.resources.displayMetrics.density).toInt()