0

I am to animate the textView which might have long text inside a CardView. I found couple of answers from this question animate textView.

<androidx.cardview.widget.CardView
android:id="@+id/lineCard"
android:layout_width="match_parent"
android:layout_height="120dp"
android:foreground="?attr/selectableItemBackground"
app:cardBackgroundColor="@color/Black">
    <TextView
        android:id="@+id/tvCallerName"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:backgroundTint="#00FFFFFF"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:textAlignment="center"
        android:textColor="@color/White"
        android:textSize="32sp"/>
</androidx.cardview.widget.CardView>

I am using ellipsize,marqueeRepeatLimit,scrollHorizontally,singleLine. But still it doesnt work. The text is displayed in two lines. What am I missinh here ? Thank you in advance.

cantona_7
  • 1,127
  • 4
  • 21
  • 40

2 Answers2

1
 <androidx.cardview.widget.CardView
 android:id="@+id/lineCard"
 android:layout_width="match_parent"
android:layout_height="120dp"
android:foreground="?attr/selectableItemBackground"
app:cardBackgroundColor="@color/Black">
 <LinearLayout 
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
    android:id="@+id/tvCallerName"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:backgroundTint="#00FFFFFF"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:textAlignment="center"
    android:textColor="@color/White"
    android:textSize="32sp"/>
   </LinearLayout>
</androidx.cardview.widget.CardView>

Added linear layout and then put textview inside that

Peter Alwin
  • 239
  • 1
  • 6
  • To be fair, I tried in a textView which isnt inside a cardView. It works fine. But inside a cardView doesnt work properly though – cantona_7 Nov 22 '19 at 10:26
  • I can't get your comment can you explain clearly what you exactly need ... – Peter Alwin Nov 22 '19 at 10:51
  • If I apply your solution to textView which is not inside a `cardView`, it is working. But inside a cardView, still doesnt work. – cantona_7 Nov 22 '19 at 11:12
0

First, create the animation in XML.

 <translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="5000"
    android:fromXDelta="100"
    android:interpolator="@android:anim/linear_interpolator"
    android:repeatCount="infinite"
    android:repeatMode="restart"
    android:toXDelta="-100" />

then add animation

textview.startAnimation(AnimationUtils.loadAnimation(this, R.anim.scroll_animation));

For Simple animation, you can use

<TextView
                android:id="@+id/attatchFilename"
                android:layout_width="170dp"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/chooseFile"
                android:layout_below="@id/txtMsg"
                android:layout_marginTop="10sp"
                android:layout_marginLeft="10dp"
                android:text=""
                android:singleLine="true"
                android:focusable="true"
                android:ellipsize="marquee"
                android:marqueeRepeatLimit="marquee_forever" />

Check out this blog as well : [https://www.journaldev.com/9481/android-animation-example][1]