带有 DialogFragment 的动画 Android
Animation With DialogFragment Android
我正在尝试通过单击带有动画的 recyclerView 项目来加载 DialogFragment,但在谷歌搜索的几个小时内我无法做到这一点。
Recyclerview 位于 viewPager 的一个片段中。
dialogFregment 是这样的:
public class adsDialogFregment extends DialogFragment {
public adsDialogFregment(){}
public static adsDialogFregment newInstance(HashMap<String,String> map ) {
//HashMap<String,String> map= new HashMap<String, String>();
Bundle args = new Bundle();
args.putSerializable("Map", map);
adsDialogFregment fragment = new adsDialogFregment();
fragment.setArguments(args);
return fragment;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_dialog_show_ads,container,false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
TextView txtTitle = (TextView)view.findViewById(R.id.txtAdTitle);
HashMap<String,String> map= (HashMap<String, String>) getArguments().getSerializable("Map");
txtTitle.setText(map.get("title"));
}
@Override
public void onResume() {
/*ViewGroup.LayoutParams params=getDialog().getWindow().getAttributes();
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
getDialog().getWindow().setAttributes((WindowManager.LayoutParams)params);*/
super.onResume();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getDialog().getWindow().getAttributes().windowAnimations= R.style.dialog_slide_animation;
}
这些是动画:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="2000"
android:fillAfter="false"
android:fromXScale="0.5"
android:fromYScale="0.5"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="-90%"
android:toXScale="1.0"
android:toYScale="1.0" />
<translate
android:duration="3000"
android:fromXDelta="-200"
android:fromYDelta="-200"
android:toXDelta="0"
android:toYDelta="0" />
</set>
和
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="20000"
android:fillAfter="false"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="-90%"
android:startOffset="200"
android:toXScale="0.5"
android:toYScale="0.5" />
<translate
android:duration="30000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="-200"
android:toYDelta="-200" />
</set>
风格是:
<style name="dialog_slide_animation">
<item name="android:windowEnterAnimation">@anim/slidestart</item>
<item name="android:windowExitAnimation">@anim/slideend</item>
</style>
但是 :
dialogFregment.show(fm, "title");
不显示为动画对话框。
我尝试了其他问题的所有解决方案,但它们对我不起作用
此致
对于动画,您必须在 onCreateDialog 方法中应用样式。我遇到了同样的问题,然后我在 onCreateDialog() 中应用了样式。
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final RelativeLayout root = new RelativeLayout(getActivity());
root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
final Dialog dialog = new Dialog(getActivity(),R.style.MyCustomTheme);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(root);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
return dialog;
}
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>
原因是设备上的动画被禁用。
我正在尝试通过单击带有动画的 recyclerView 项目来加载 DialogFragment,但在谷歌搜索的几个小时内我无法做到这一点。 Recyclerview 位于 viewPager 的一个片段中。 dialogFregment 是这样的:
public class adsDialogFregment extends DialogFragment {
public adsDialogFregment(){}
public static adsDialogFregment newInstance(HashMap<String,String> map ) {
//HashMap<String,String> map= new HashMap<String, String>();
Bundle args = new Bundle();
args.putSerializable("Map", map);
adsDialogFregment fragment = new adsDialogFregment();
fragment.setArguments(args);
return fragment;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_dialog_show_ads,container,false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
TextView txtTitle = (TextView)view.findViewById(R.id.txtAdTitle);
HashMap<String,String> map= (HashMap<String, String>) getArguments().getSerializable("Map");
txtTitle.setText(map.get("title"));
}
@Override
public void onResume() {
/*ViewGroup.LayoutParams params=getDialog().getWindow().getAttributes();
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
getDialog().getWindow().setAttributes((WindowManager.LayoutParams)params);*/
super.onResume();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getDialog().getWindow().getAttributes().windowAnimations= R.style.dialog_slide_animation;
}
这些是动画:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="2000"
android:fillAfter="false"
android:fromXScale="0.5"
android:fromYScale="0.5"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="-90%"
android:toXScale="1.0"
android:toYScale="1.0" />
<translate
android:duration="3000"
android:fromXDelta="-200"
android:fromYDelta="-200"
android:toXDelta="0"
android:toYDelta="0" />
</set>
和
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="20000"
android:fillAfter="false"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="-90%"
android:startOffset="200"
android:toXScale="0.5"
android:toYScale="0.5" />
<translate
android:duration="30000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="-200"
android:toYDelta="-200" />
</set>
风格是:
<style name="dialog_slide_animation">
<item name="android:windowEnterAnimation">@anim/slidestart</item>
<item name="android:windowExitAnimation">@anim/slideend</item>
</style>
但是 :
dialogFregment.show(fm, "title");
不显示为动画对话框。 我尝试了其他问题的所有解决方案,但它们对我不起作用
此致
对于动画,您必须在 onCreateDialog 方法中应用样式。我遇到了同样的问题,然后我在 onCreateDialog() 中应用了样式。
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final RelativeLayout root = new RelativeLayout(getActivity());
root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
final Dialog dialog = new Dialog(getActivity(),R.style.MyCustomTheme);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(root);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
return dialog;
}
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>
原因是设备上的动画被禁用。