first of all I am using API 28 (Android 9.0) I want my second activity to appear from left to right when I click the menu button on mainActivity. I have overrided the pending transition in main activity like below:
startActivity(myintent);
this.overridePendingTransition(R.anim.left_to_right, R.anim.no_move);
the left_to_right.xml with duration 100ms(that doesnt seems to be 100ms, its almost 1 second, but animation works fine):
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="100"
android:fromYDelta="0%"
android:fromXDelta="-100%"
android:toXDelta="0%"
android:toYDelta="0%">
</translate>
</set>
and no_move.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%"
android:toYDelta="0%"
android:fromXDelta="0%"
android:toXDelta="0%">
</translate>
</set>
this is my theme.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Chess" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="android:windowActivityTransitions">true</item>
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
the activity starts how I want(animation) but the only problem is its duration.it takes like 1 second for compelete translate.
there is no extra code to mention here, all i add was that 2 anim file and overriding pendingTranstition
plus setting windowActivityTranstition to True in themes.xml
WHAT I WANT TO DO...
the animation I want here is like when you click the menu button(on the top and left) in Telegram app, the menu shows up smoothly, I want something beautifule like that.
so if there is a better way to do such things or if telegram uses another way for this beautiful animation please let me know.
thanks in advance.
Use one activity
with DrawerLayout view
for that left menu. It has open/close functions, fade effect etc. Telegram app uses their own custom view for that menu here it is. You can also check source code of their activity here (check DrawerLayoutAdapter
, DrawerLayoutAdapter
variables)