I have a ListPopupMenu with code as below
public void showPopupMenu(View view) {
ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
listPopupWindow.setAdapter(new CollectionItemMenuAdapter(getActivity(), popupMenuList));
listPopupWindow.setWidth((int) getResources().getDimension(R.dimen.menu_width));
listPopupWindow.setHeight(WRAP_CONTENT);
listPopupWindow.setVerticalOffset((int) getResources().getDimension(R.dimen.menu_vertical_offset));
listPopupWindow.setHorizontalOffset((int) getResources().getDimension(R.dimen.menu_horizontal_offset));
listPopupWindow.setAnchorView(view);
listPopupWindow.show();
}
The result is as below, when click on the setting (in the gif, the first one), the popup menu appear.
However the menu animation appears from Right to Left. I would prefer it to show from Left to Right (like appearing from the setting button). Could I achieve that without creating a custom animation for it?
p/s: I tried custom animation using listPopupWindow.setAnimationStyle(...)
, also not working
I made in this way.
First, make animation set in res/anim folder
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale android:fromXScale="0" android:fromYScale="1"
android:toXScale="1" android:toYScale="1"
android:duration="700"
/>
</set>
second, add style in res/values/styles.xml
<style name="Animation">
<item name="android:windowEnterAnimation">@anim/animation</item>
</style>
and use setAnimationStyle.
popupWindow.setAnimationStyle(R.style.Animation);
This is PopupWindow. but i think they are both the same way.
good luck !!
Apparently my problem is mainly due to sending the wrong view over to listPopupWindow.setAnchorView(view);
. I need to send the "setting-image" view instead of the "parent-list-view".
By sending the right view, I now have the animation starting from the right source i.e. the point of the setting image. The fixed animation is shown below
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With