显示带有动画的DialogFragment

时间:2019-02-01 10:27:52

标签: android android-animation android-dialogfragment

如何显示buildToolsVersion以及从点击点开始放大的放大动画?

这是我从活动中调用对话框的方式

DialogFragment

这是DialogFragment dialog = new MyDialogFragment(); Bundle args = new Bundle(); // put arguments into the bundle dialog.setArguments(args); dialog.show(getSupportFragmentManager(), null); 的基本代码

DialogFragment

我尝试在public class MyDialogFragment extends AppCompatDialogFragment{ Bundle mArgs; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // remove the title space setStyle(AppCompatDialogFragment.STYLE_NO_TITLE, 0); mArgs = getArguments(); // extract the values from the bundle } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.dialog_add_edit_pool, container, false); // find views by ids // handle clicks and inputs return view; } } 中使用以下代码,但它不起作用

MyDialogFragment

@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); getDialog().getWindow().getAttributes().windowAnimations= R.style.MyCustomTheme; }

values\styles.xml

<style name="MyCustomTheme" parent="@android:style/Theme.Panel"> <item name="android:windowAnimationStyle">@style/MyAnimation.Window</item> </style> <style name="MyAnimation.Window" parent="@android:style/Animation.Activity"> <item name="android:windowEnterAnimation">@anim/anim_in</item> <item name="android:windowExitAnimation">@anim/anim_out</item> </style>

anim\anim_in.xml

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/linear_interpolator" android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" android:toYScale="1.0" android:fillAfter="false" android:startOffset="200" android:duration="200" android:pivotX = "50%" android:pivotY = "-90%" /> <translate android:fromYDelta="50%" android:toYDelta="0" android:startOffset="200" android:duration="200" /> </set>

anim\anim_out.xml

有解决方案吗?

0 个答案:

没有答案