Description
AchievementsFragment.kt lines 76–87 set the badge image size at runtime using DisplayMetrics pixel calculations:
val displayMetrics = DisplayMetrics()
requireActivity().windowManager.defaultDisplay.getMetrics(displayMetrics)
val height = displayMetrics.heightPixels
val width = displayMetrics.widthPixels
// TODO REMOVE
val params = binding.achievementBadgeImage.layoutParams as ConstraintLayout.LayoutParams
params.height = (height * BADGE_IMAGE_HEIGHT_RATIO).toInt()
params.width = (width * BADGE_IMAGE_WIDTH_RATIO).toInt()
binding.achievementBadgeImage.requestLayout()
The constants are BADGE_IMAGE_WIDTH_RATIO = 0.4 and BADGE_IMAGE_HEIGHT_RATIO = 0.3.
This is a legacy pre-ConstraintLayout approach. The view is already inside a ConstraintLayout (fragment_achievements.xml), so the same effect can be achieved declaratively using layout_constraintWidth_percent and layout_constraintHeight_percent.
Proposed fix
In fragment_achievements.xml, change achievement_badge_image from fixed 150dp dimensions to:
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintWidth_percent="0.4"
app:layout_constraintHeight_percent="0.3"
Remove lines 76–87 from AchievementsFragment.kt and the two companion constants.
Benefits
- Removes
windowManager.defaultDisplay usage (deprecated in API 30+)
- Declarative sizing is easier to read and maintain
- Visual-only change; no behavioural impact
Tested on: Pixel 6, Android 16.
Description
AchievementsFragment.ktlines 76–87 set the badge image size at runtime usingDisplayMetricspixel calculations:The constants are
BADGE_IMAGE_WIDTH_RATIO = 0.4andBADGE_IMAGE_HEIGHT_RATIO = 0.3.This is a legacy pre-ConstraintLayout approach. The view is already inside a
ConstraintLayout(fragment_achievements.xml), so the same effect can be achieved declaratively usinglayout_constraintWidth_percentandlayout_constraintHeight_percent.Proposed fix
In
fragment_achievements.xml, changeachievement_badge_imagefrom fixed150dpdimensions to:Remove lines 76–87 from
AchievementsFragment.ktand the two companion constants.Benefits
windowManager.defaultDisplayusage (deprecated in API 30+)Tested on: Pixel 6, Android 16.