I’ve successfully implemented left-to-right animation, but I’m facing issues with implementing a Vertical animation.
In Android there is a inbuild function for horizonatal scrolling which is
android:marqueeRepeatLimit="marquee_forever"
android:padding="10dp"
android:scrollHorizontally="true"
But I have to do from low to up. Like this below ex:
Does anyone have ideas on how to achieve this? I’ve come across several suggestions, but none of them have worked so far.
**
one of the attempt i’m sharing through using AI.**
package com.brainintelcorp.brainintel
import android.content.Context
import android.util.AttributeSet
import android.view.animation.TranslateAnimation
import androidx.appcompat.widget.AppCompatTextView
class VerticalMarqueeTextView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : AppCompatTextView(context, attrs, defStyleAttr) {
init {
isSingleLine = true
setHorizontallyScrolling(true)
startMarquee()
}
private fun startMarquee() {
val translateAnimation = TranslateAnimation(
0f, 0f, height.toFloat(), -height.toFloat()
).apply {
duration = 10000 // Set your desired speed
repeatCount = TranslateAnimation.INFINITE
}
startAnimation(translateAnimation)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
clearAnimation()
}
}
now we have to change in xml also.
<com.brainintelcorp.brainintel.VerticalMarqueeTextView
android:id="@+id/tvQuestionContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeMinTextSize="14sp"
android:autoSizeStepGranularity="1sp"
android:autoSizeTextType="uniform"
android:padding="10dp"
android:text="@string/question_content"
android:textColor="@color/primaryColor"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/imageLogo" />
I have changed the xml for the vertical animation. But i have no idea how can i start the animation as a basic knowledge on kotlin.
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvQuestionContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_marginTop="20dp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeMinTextSize="14sp"
android:autoSizeStepGranularity="1sp"
android:autoSizeTextType="uniform"
android:ellipsize="none"
android:padding="10dp"
android:text="@string/question_content"
android:textColor="@color/primaryColor"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/imageLogo" />
I’ve tried making changes in the activity using AI suggestions, but they didn’t work. Does anyone have ideas on how to achieve this?