android-layout - PopupWindow 动画在 Android Studio 4.2.1 中不起作用
问题描述
我想要的是从下到上出现的弹出窗口
res/anim/appear.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<scale
android:duration="1000"
android:fillAfter="false"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="90%"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
res/anim/disapper.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<scale
android:duration="1000"
android:fillAfter="false"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:pivotX="50%"
android:pivotY="90%"
android:toXScale="0.0"
android:toYScale="0.0" />
</set>
res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AnimationPopup">
<item name="android:windowEnterAnimation">@anim/appear</item>
<item name="android:windowExitAnimation">@anim/disappear</item>
</style>
</resources>
MainActivity.java。
popWindow.setAnimationStyle(R.style.AnimationPopup);
似乎不起作用。
我已经搜索了互联网,但仍然找不到解决方案。
public class MainActivity extends AppCompatActivity {
private Button btn_show;
private MainActivity mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = MainActivity.this;
btn_show = (Button) findViewById(R.id.btn_show);
btn_show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
initPopWindow(v);
}
});
}
private void initPopWindow(View v) {
View view = LayoutInflater.from(mContext).inflate(R.layout.item_popup, null, false);
TextView Rename = (TextView) view.findViewById(R.id.Rename);
TextView SaveTo = (TextView) view.findViewById(R.id.SaveTo);
final PopupWindow popWindow = new PopupWindow(view,
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
popWindow.setAnimationStyle(R.style.AnimationPopup);
popWindow.showAsDropDown(v, 200, 0);
}
解决方案
推荐阅读
- c# - 如何使用模拟在具有 UNC 的远程计算机上操作文件/目录?
- c++ - 强制从函数中推导模板以在适用的情况下生成 const 引用
- java - 一个线程只有在我强制它进行调试时才会执行,有什么原因吗?
- javascript - 如何计算数组中有多少对数字
- php - Symfony4 部署到共享主机得到错误 500
- python - MobilenetSSDv2 冻结迁移学习
- javascript - 鼠标向上事件在 SVG 中无法正常工作
- vb.net - 从 Webrequest 字符串中提取信息的最佳方法
- python - 如何在 Jupyter Notebooks 中使用 Pylint 或其他 linter?
- c - 如何找到第n个数字?