Smooth way to transition one line Textview to 2 line Textview

Viewed 96

I am transitioning two views, an ImageView and a Textview, using

ActivityOptionsCompat options = ActivityOptionsCompat.
                    makeSceneTransitionAnimation((Activity) context, viewPairs.toArray(new Pair[viewPairs.size()]));
context.startActivity(intent, options.toBundle());

The Image works fine, but the textview is transitioning from a 2 line textview, to a one line text view and that works fine, the problem is, when it transitions back from the one line to the 2 line, it is like choppy and seems like it glitches out a bit. I was wondering if there is a way to smooth it out and make it more of a pleasant transition. This call above is in a static method, and it is called from a Recycleview adapter.

Thank you for your time

3 Answers

do this :

textview.setPaintFlags(textview.getPaintFlags() | Paint.ANTI_ALIAS_FLAG);

Also check out this answer

What if you add attribute like this to the View :

<ImageView
..
android:animateLayoutChanges="true" />

You can use a ViewSwitcher with an animation:

    <ViewSwitcher android:id="@+id/text_switcher"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:measureAllChildren="false"
        android:inAnimation="@android:anim/fade_in"
        android:outAnimation="@android:anim/fade_out">
        <TextView android:id="@+id/short_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <TextView android:id="@+id/long_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </ViewSwitcher>

Switch the text like this:

mSwitcher = findViewById(R.id.text_switcher);
mSwitcher.showNext();
Related