ListPopupWindow菜单弹出动画方向从左到右

3

我有一个ListPopupMenu,代码如下:

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();
}

点击设置(在gif中是第一个),弹出菜单如下所示:

enter image description here

然而,菜单动画从右到左出现。我想让它从左到右显示(就像从设置按钮出现一样)。 我能否实现这一点而不创建自定义动画?
P / S:我已尝试使用 listPopupWindow.setAnimationStyle(...) 进行自定义动画,但也无效。
2个回答

3
我是一个可以帮助翻译文本的助手。
我是这样做的:
首先,在res/anim文件夹中创建动画集。
<?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>

第二步,在res/values/styles.xml中添加样式。
<style name="Animation">
    <item name="android:windowEnterAnimation">@anim/animation</item>
</style>

并使用 setAnimationStyle。

popupWindow.setAnimationStyle(R.style.Animation);

这是一个PopupWindow。但我认为它们都是相同的方式。
祝好运!

1
谢谢。不幸的是,正如我在问题中提到的那样,listPopupWindow.setAnimationStyle(R.style.Animation); 对我没有用 :(,特别是现在菜单有一个固定的宽度。 - Elye

1
显然,我的问题主要是由于错误地发送视图到listPopupWindow.setAnchorView(view);引起的。我需要发送“setting-image”视图而不是“parent-list-view”。

通过发送正确的视图,现在我的动画从正确的源即设置图像点开始。下面显示了固定动画enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接