Skip to content

tech debt: replace runtime pixel sizing in AchievementsFragment with ConstraintLayout percentage constraints #6898

Description

@chrisdebian

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions