AndroidCoder
AndroidCoder

Reputation: 2735

Positioning an Overlaying or floating View Above another view in Layout

In an Android application, I have a layout containing a TextView at the top and two elements beneath it: an icon and another TextView. The second TextView displays a numerical value that undergoes a counter animation using ValueAnimator.

Upon completion of this counter animation, in doOnEnd blcok, I aim to overlay an additional animation. The animation file is available with me.

Specifically, I seek guidance on positioning this overlay animation as follows:

  1. The overlay animation should float above the numerical value displayed by the second TextView.
  2. It must not disrupt the layout flow of the page, akin to absolute positioning in web development, ensuring that it remains visually distinct from the layout while anchored to the specified number.

How can I achieve this positioning and overlay of the animation in my Android application? Any insights or guidance would be appreciated. Thank you.

Note - I plan to use the constrain layout. However, if this is possible by using other layouts, I would be happy to use it.

Note - Need to consider text resize / font scaling while implementating.

enter image description here

Upvotes: 0

Views: 70

Answers (1)

Purple6666
Purple6666

Reputation: 402

you can match the constraints of your animation to match the positioning of your second one.

    android:id="@+id/animation"
    app:layout_constraintBottom_toBottomOf="second_text"
    app:layout_constraintEnd_toEndOf="second_text"
    app:layout_constraintTop_toTopOf="second_text"
    app:layout_constraintStart_toTopStart="second_text"

and then use app:layout_constraintHorizontal_bias="float_value" and app:layout_constraintVertical_bias="float_value" to move the first text in the correct position. You might have to increase the top padding of the second text view.

Upvotes: 0

Related Questions