我用来给片段充气的动画在对话框上不起作用

时间:2019-07-10 12:34:59

标签: android android-fragments

我正在处理一个菜单片段,当单击一个按钮时,它覆盖了屏幕的一半。通过使用片段无法满足菜单要求之后,我决定切换到自定义对话框。使用自定义对话框,我能够使菜单按我希望的方式运行,但是当显示或关闭自定义对话框时,我无法获得动画效果(在以前使用的片段上效果很好)。该应用程序可以完美运行,但是动画不会出现。这是什么问题?

这是我用于自定义对话框的两个功能:

private void initDialog() {

dialog = new Dialog(this, R.style.DialogCustomTheme);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_menu);

// positioning
WindowManager.LayoutParams WMLP = dialog.getWindow().getAttributes();
WMLP.x = -300;   //x position
WMLP.y = 100;   //y position
dialog.getWindow().setAttributes(WMLP);


dialog.getWindow().getAttributes().windowAnimations = R.anim.enter_from_left;
dialog.show();

initDialogViews();

}

private void initDialogViews() {

    dialog.findViewById(R.id.menuOption1).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Most Popular Items", Toast.LENGTH_LONG).show();
            dialog.getWindow().getAttributes().windowAnimations = R.anim.exit_to_left;
            dialog.dismiss();
        }
    });

    dialog.findViewById(R.id.menuOption2).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Top Rated Items", Toast.LENGTH_LONG).show();
            dialog.getWindow().getAttributes().windowAnimations = R.anim.exit_to_left;
            dialog.dismiss();
        }
    });

    dialog.findViewById(R.id.menuOption3).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Cheapest Items", Toast.LENGTH_LONG).show();
            dialog.getWindow().getAttributes().windowAnimations = R.anim.exit_to_left;
            dialog.dismiss();
        }
    });

    dialog.findViewById(R.id.menuOption4).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Free Items", Toast.LENGTH_LONG).show();
            dialog.getWindow().getAttributes().windowAnimations = R.anim.exit_to_left;
            dialog.dismiss();
        }
    });

    dialog.findViewById(R.id.menuLogIn).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Feature still not added!", Toast.LENGTH_LONG).show();
            dialog.getWindow().getAttributes().windowAnimations = R.anim.exit_to_left;
            dialog.dismiss();
        }
    });
}

enter_from_left.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
    android:fromXDelta="-100%"
    android:toXDelta="0%"
    android:fromYDelta="0%"
    android:toYDelta="0%"
    android:duration="2000"
    />

exit_to_left.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:shareInterpolator="false">
<translate
    android:fromXDelta="0%"
    android:toXDelta="-100%"
    android:fromYDelta="0%"
    android:toYDelta="0%"
    android:duration="2000"
    />

0 个答案:

没有答案