-1

I am currently making a chat app and i want to add a feature like telegram. As you can see here, there is a animation in the recycler view as if i=t zooming or decreasing its size. You can also notice that animation while opening and closing the navigation drawer. I too tried to do that using this but i get no animation in the recycler view. See this. Actually not this but like this. I took this gif from the README of the repo. So is that possible? If so, can you please tell me a simple implementation ?

Thanks in advance and i will be waiting

2 Answers2

0

Add overridePendingTransition in onBackPressed() method:

@Override
public void onBackPressed() {
    super.onBackPressed();
    overridePendingTransition(0, R.anim.slide_out_right);
}

res->anim->slide_out_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromXDelta="0"
        android:toXDelta="100%p" />
</set>
Android Geek
  • 8,956
  • 2
  • 21
  • 35
  • thanks for the answer but i want to slide like telegram. not on back pressed thing. but this one helped too ! –  Feb 09 '22 at 14:31
0

To me it looks like an Activity transition where the translateZ value is modified. But since the Telegram Android client is open source, we can just take a look at it.

It looks like the Telegram devs use a lot of custom code instead of relying on the android SDK.

The DialogsActivity which extends a BaseFragment but is neither an Android Activity nor an Android Fragment since BaseFragmentdoesn't extend any of them, has the following method for the transition:

    private void setSlideTransitionProgress(float progress) {
        if (SharedConfig.getDevicePerformanceClass() == SharedConfig.PERFORMANCE_CLASS_LOW) {
            return;
        }
        slideFragmentProgress = progress;
        if (fragmentView != null) {
            fragmentView.invalidate();
        }

        if (filterTabsView != null) {
            float s = 1f - 0.05f * (1f - slideFragmentProgress);
            filterTabsView.getListView().setScaleX(s);
            filterTabsView.getListView().setScaleY(s);
            filterTabsView.getListView().setTranslationX((isDrawerTransition ? AndroidUtilities.dp(4) : -AndroidUtilities.dp(4)) * (1f - slideFragmentProgress));
            filterTabsView.getListView().setPivotX(isDrawerTransition ? filterTabsView.getMeasuredWidth() : 0);
            filterTabsView.getListView().setPivotY(0);
            filterTabsView.invalidate();
        }
    }
Alexander Hoffmann
  • 5,104
  • 3
  • 17
  • 23
  • thanks for the answer. but how can use this method ? where should i give the progress ? How do i know the progress of it being swiped ? –  Feb 09 '22 at 14:32