I am creating video app like TikTok and need to implement text marquee in TextView
. I also recorded video for doing same like
So I created TextView
code:
<LinearLayout
android:id="@+id/llSoundDesc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/tabLayout"
app:layout_constraintEnd_toStartOf="@+id/layoutSound"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_gravity="center"
android:contentDescription="@string/app_name"
android:src="@mipmap/ic_music" />
<TextView
android:id="@+id/tvSoundDesc"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginBottom="2dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="@string/orignal_soun_by"
android:textColor="@color/white" />
</LinearLayout>
And from HomeActivity.kt
:
class HomeActivity : AppCompatActivity() {
private lateinit var mBinding: ActivityHomeBinding
private var isPlay = false
@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBinding = ActivityHomeBinding.inflate(layoutInflater)
setContentView(mBinding.root)
mBinding.tvSoundDesc.isSelected = true
}
}
So, this code will show text in marquee continuously but not smoothly after one marquee freeze for few millis and then start again and there is also another problem is how can I play/pause like TikTok app?
I also tried:
btn.setOnClickListener {
if (isPlay) {
isPlay = false
mBinding.tvSoundDesc.isSelected = false
} else {
isPlay = true
mBinding.tvSoundDesc.isSelected = true
}
}
but its start from first position not from current position like TikTok App! And I also tried <marquee>Your text</marquee>
of HTML
and set to TextView
but it also not working. So, is there any other way to set marquee
like this?