Android: Smooth DrawerLayout animations on Fragment Change - android

I'm working on an Android app that uses a navigation drawer and multiple navigation menu items. Inflating the views and running onCreate() takes some time, which makes the drawer close animation very laggy. I'm already working on optimizing the fragment layout itself to reduce jank, but the animation is still laggy.
My quick fix was adding a drawer listener and calling getSupportFragmentManager().beginTransaction().replace(...).commit() on drawer close. However the problem with this is that the previous fragment still remains in the UI for a few milliseconds after the drawer is closed, which looks arguably worse than with the laggy animation.
How is it possible to ensure a smooth drawer close animation and concurrently load the new fragment - or is there another way to make the UI transitions look more natural?

Related

Tab layout transition delay is very fast

Am using custom animations in view pager and these animations works perfectly when swiping left or right,but when pressing on the tabs itself without swiping, the animations is done very fast causing damage to the eye, so is there any function to change the delay when pressing on the tabs ?
The first thing comes to my mind is making delay with a handler but delaying the transition between pages may cause unexpected result because of user behavior like clicking buttons very fast. I recommend making the view pager's transition animation a little slower. You can achieve such a behavior by using the Slowing speed of Viewpager controller in android

What should I do to a get smooth navigation drawer close on navigation item click

I have used basic navigation drawer generated in android studio. I noticed my navigation slider slides off smooth and lag sometimes. I found that the lag cause of the LayoutInflater I used to inflate another layout on my fragment.
What I have done is,
ViewGroup myLayout = view.findViewById(R.id.current_layout);
View mayLayoutTwo = LayoutInflater.from(CurrentFragment.this.getActivity()).inflate(R.layout.cardview_to_inflate, myLayout, false);
myLayout.addView(mayLayoutTwo);
I want to know is that possible to avoid that lag on navigation drawer slide. Help me to fix this issue.
Navigation drawer with multiple fragments is common usage. So based on your fragments loading at onCreate() lifecycle stage, your Naviagtion drawer may not smooth while closing.
So solution 1 :
Avoid heavy loading at your fragment initiate state. (e.g loading data asynchronously.)
Solution 2 :
Display place holder view (e.g whit screen) while navigation drawer is closing. Once NV drawer is closed, show your fragment.
You can use animation for fragment transition to give the better UX, since the default one looks some kinda awkward transition so giving your own transition will make the user feel some more smoothness, and yes avoid making the larger async calls on initiating the fragment.

Android jfeinstein10/SlidingMenu's animation is not smooth when changes fragment

I use jfeinstein10/SlidingMenu as my slidingmenu for my app and the slidingmenu will change different fragment for a activity.When the fragment contains only one or two items it seems good.But if I tried to make the fragment contains more thing ,the slidingmenu will be a short stop when I change the fragment.The animation is not smooth
Is there anyway to slove the problem?Thanks.
I experience same animation lag when I'm showing heavy fragment.
I tried to close menu with animation and show fragment with animation at same time. The animation was laggy, even with native drawer.
So the way to go is:
set menuOnClose listener
on menu item click remember the choice
close menu
in onCloseListener show fragment.
that works great for me.
I have a somewhat clunky solution for this but it works okay.
I use a base class for my fragments which is called BaseFragment. In this class I override the onResume method and close the menu if it is showing:
#Override
public void onResume() {
super.onResume();
if(sm.isMenuShowing()){
sm.showContent();
}
}
sm is a reference for a SlidingMenu from the SlidingFragmentActivity.
This will make the animation smoother but it will create a small delay between the click on a menu button and the start of the close animation. In my case this worked better then when the animation stops mid-animation.

Fragment layout loading delay

As per the answer here How to make fragments load faster? I put all tasks in an async task and still there's a delay while loading fragment. The fragment is a calculator, with 30 buttons and two text views.
I have a sliding drawer and the delay occurs when I choose the item that opens the calculator fragment. The sliding drawer lags while returning to hidden position.
I use fragmentTransaction.replace(R.id.content_frame, calc_frag) in a fragment activity to load the fragment.
I removed all the code in the fragment except inflating the layout. Lag.
How I get rid of the delay/lag?
Without code its hard to say, maybe you should look at ProgressBar and hold on showing the fragment until the contents have fully loaded?

android picture loading progress update parent view

I'm a bit new in android developement and have got issue with updating view which I cannot resolve myself.
What I've got is mapview, on the map I have sliding drawer with listview. The list view is build up by custom adapter which puts some texts and uses imageLoader object to load picture from url in backround. In the listview row layout I have got also progresloader placed in relative view on top of picture. This is default visible and is put GONE on imageloader backround thread when loaded picture is put to imageview.
So you get the idea, it is to show progres of loading picture and loading them on backround to have listview built up quickly.
To my problem. The sliding drawer is customized to show part of it (1 item from list + a little from next) when closed and full screen when opened. When user click on map icon where there are more items under it, it loads up listview in closed sliding drawer. The progres loader in it is not rotating, when I open sliding drawer, loading progresses are rotating, they are rotating also when moving drawer and they are rotating also when drawer is closed and there is any interaction with ui like moving map or so.
Was trying to figure out what to do, found out that when I add invalidate of content on dispatch draw on sliding drawer that makes it to refresh sliding drawer again and to fire dispatch draw again, loading progresses in lstview are rotating but this is not very good as basically I created infinite loop and updating sliding drawer forever, this uses up all cpu.
Updating sliding drawer or listview should be triggered by progress loaders but it is somehow not ;o( It does work well on open drawer and also on closed but I have to interact with UI than it fires dispatch draw on slider which redraws it children and porgresses ar erotating.
Can someone give me a clue how to make the drawer to update when loaders are there visible?
thanks a lot.

Categories

Resources