Is there a way to animate PopupWindow when issuing update() method? I'm changing my popup's position there, so it would be nice if I could smoothly slide the popup to its destination instead of just "jumping". I know I can easily animate the PopupWindow's entering and exiting via adding these items to its style:
<style name="MyPopup">
<item name="#android:windowEnterAnimation">#anim/slide_in_right</item>
<item name="#android:windowExitAnimation">#anim/slide_out_to_right</item>
</style>
But I'm interested in its position updating animation.
Related
I noticed that by default, when a bottom sheet dialog is shown, the scrim just pop up without any animation, which is not a good user experience. So I was wondering how to show the scrim with animation. Any suggestion?
You can use
getDialog().getWindow().getAttributes().windowAnimations = *Your animation here*(
For example, R.style.myAnimation
<style name="myAnimation">
<item name="android:windowEnterAnimation">#anim/up</item>
<item name="android:windowExitAnimation">#anim/down</item>
</style>
)
I have an activity with a DrawerLayout but whenever it opens there is a delay like a split-second where the screen is white then my screen is drawn.
This happens after the Transition finishes. So it sort of looks like the screen animation transition is jumping.
I tried putting this on my OnCreate after binding the views with ButterKnife but it did nothing.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
postponeEnterTransition();
drawerLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
public boolean onPreDraw() {
drawerLayout.getViewTreeObserver().removeOnPreDrawListener(this);
startPostponedEnterTransition();
return true;
}
});
}
Yes I am optimizing it for Lollipop, and for pre-Lollipop devices I am jsut using overridePendingTransitionsand it works fine. My problem is only on Lollipop devices.
Btw, my Enter and Exit transitions are both fade_in_outdefined in xml and specified in styles
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorAccent">#color/pink</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowContentTransitions">true</item>
<!-- specify enter and exit transitions -->
<!-- options are: explode, slide, fade -->
<item name="android:windowEnterTransition">#transition/fade_in_out_transition</item>
<item name="android:windowExitTransition">#transition/fade_in_out_transition</item>
<!-- specify shared element transitions -->
<item name="android:windowSharedElementEnterTransition">#transition/change_clip_bounds</item>
<item name="android:windowSharedElementExitTransition">#transition/change_clip_bounds</item>
<item name="android:windowSoftInputMode">stateAlwaysHidden|adjustResize</item>
</style>
I finally found a solution to this. I don't know why or how it worked out but I just know that it removed the delay in the animations. I added a handler in the OnCreate of the activity that would run the other statements for setting up, i.e. adding the initial fragment into view, after 300ms
Handler mHandler = new Handler();
mHandler.postDelayed(new Runnable() {
#Override
public void run() {
switchFragment();
}
}, 300);
Maybe its because lollipop has default layoutTransition on UI elements, have you tried?
drawerLayout.setLayoutTransition(null)
I would change your exit transition:
item name="android:windowExitTransition">#transition/fade_in_out_transition</item>
item
To window return:
name="android:windowReturnTransition">#transition/fade_in_out_transition</item>
When you are using window exit, the visibility of the window is changed to invisible briefly before your next transition starts.
Sets the Transition that will be used to move Views out of the scene
when the fragment is removed, hidden, or detached when not popping
the back stack. The exiting Views will be those that are regular
Views or ViewGroups that have isTransitionGroup() return true.
Typical Transitions will extend Visibility as exiting is governed by
changing visibility from VISIBLE to INVISIBLE. If transition is null,
the views will remain unaffected.
setExitTransition
Returning the transition handles the window closing, as opposed to exiting and does not affect the window visibility.
Reference to a Transition XML resource defining the desired
Transition used to move Views out of the scene when the Window is
preparing to close. Corresponds to
setReturnTransition(android.transition.Transition).
android:windowReturnTransition
I would also recommend using reenter to manage back presses.
Reference to a Transition XML resource defining the desired Transition
used to move Views in to the scene when returning from a
previously-started Activity. Corresponds to
setReenterTransition(android.transition.Transition).
android:windowReenterTransition
Understanding exit/reenter shared element transitions
You can also set a bool value that will allow the transitions to overlap, however the overlap may be too long
for what you want.
setAllowEnterTransitionOverlap(boolean)
Also I'd upgrade the lollipop to 5.0.1
There are bugs in 5.0.0 that have been fixed in 5.0.1
This blog by Linton Ye covers in detail the issues surrounding Lollipop transitions and bugs.
My Journey to Lollipop Transitions: part 1
I've been working on an app and I've reaching the point where it requires me to display a menu window in the middle of the screen.
I've been using an AlertDialog object filled with a custom View but now it was required of me to "surround" the window with a semi-transparent white glow as opposed to the default grayish one. I did a similar with the fade-in color of some navigation drawers I have on my app but in that case I had a specific method to quickly help me solve that problem. So far I haven't found anything that helps me solve this one.
I tried creating a default style with a new "windowBackground" value but I encountered 3 problems from the get-go:
I'm no longer able to shut the AlertDialog down by clicking outside the layout (I'm guessing because by changing the color that way everything is now the layout)
The menu window is now surrounded by a black outline that wasn't there before
By using the filtering search inside the layout, which manipulates the members of a list, the window collapses on itself
Is there any way to accomplish what I want more or less directly?
I'm not really sure about it, but you can use this in your styles.xml
<style name="MyDialogTheme" parent="android:Theme.AppCompat.Light.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#color/your_light_color</item>
<item name="android:backgroundDimEnabled">false</item>
And if you want to dismiss the dialog when clicking outside, use this:
dialog.setCanceledOnTouchOutside(true);
or
<item name="windowCloseOnTouchOutside">true</item>
in your styles.xml
I put together a very simple app that uses shared element transitions when starting an activity with Dialog theme (source code on github).
I got the following result:
As you can see there are 2 problems with the transition/animation:
The animation is only visible in the area of the dialog activity so it clips and looks ugly.
There is no transition/animation when I tap outside the activity to
go back.
How can I fix these problems? Any help would be appreciated.
EDIT: After Quanturium's answer I did the following things to get it working:
Use the following theme instead of a Dialog theme:
<style name="AppTheme.Transparent" parent="AppTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
Use a CardView as the background for Dialog look and for rounded corners and shadows.
Call finishAfterTransition(); when user taps outside the CardView.
Now it looks like this (code), the CardView needs refining to better match the Dialog, but it's working at least.:
An activity transition works like this. When you start your second activity, it is displayed on top of your first one with a transparent background. The shared elements are positioned the same way they are on the first activity and then animated to the correct position specified on the second activity.
In your case you are using android:theme="#style/Theme.AppCompat.Dialog" which mean the size of the second activity's drawing area is smaller than the one from the first activity. This explains the clipping and the no transition when clicking outside.
What you want to do is get rid of that theme, and implement your own layout with a dark background / shadow in order to be able to execute your smooth transition.
I have a problem: I have a ListView with a MULTI_CHOICE listener that opens up the ContextualActionBar. For each item in this list I've setted a backround on the root layout. This is the XML:
<item android:drawable="#color/light_blue_alpha"
android:state_activated="true"/>
<item android:drawable="#color/light_blue"
android:state_pressed="true"/>
<item android:drawable="#drawable/card_background"/>
In this case the default background is a card layout (basically white). When the item is pressed the background is a full light blue. When activated (through CAB choice) the background is a ligh blue with 0.5 alpha.
This is what is happening:
I start the CAB. If I select a new item during the CAB, the item changes its background to light_blue (while pressed). When I release the finger it changes to the default background card_background. A few milliseconds later it gets activated and then changes to light_blue_alpha
So basically I'm getting this kind of flickering blue-white-blue. What I want to achieve is to "remove" the white background transaction. I see for example that Gmail app does exactly what I want to do.
How can achieve that? Thank you!!
EDIT:
I tried moving all to a root listSelector. This is the selector:
<item android:state_pressed="true" android:drawable="#color/light_blue"/>
<item android:state_activated="true" android:drawable="#color/light_blue_alpha"/>
<item android:drawable="#android:color/transparent"/>
I also set drawOnTop to true, and the pressed background is correctly applied. But the state_activated doesn't! When I start the CAB, the item returns to its default background. Why doesn't it take the state_activated background??
take one variable in adapter named as selected_position, assign selected position value in this variable.
call notifydatasetchanged method for adapter
in get view method put condition like
if(selected_position == position)
{
change back ground color of list item
}
else
{
set default background color
}
Hope this helps