3

I am trying to load a DialogFragment by clicking on recyclerView items with animation but in hours of googling i cant do that. Recyclerview is in a on of fregments of a viewPager. the dialogFregment is this :

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

and these are animations :

<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>

and

<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>

and the style is :

 <style name="dialog_slide_animation">
    <item name="android:windowEnterAnimation">@anim/slidestart</item>
    <item name="android:windowExitAnimation">@anim/slideend</item>
</style>

but the :

  dialogFregment.show(fm, "title");

not show as animation Dialog. i tried all solutions in other questions but they didnt work for me

Best Regards

Hamed
  • 79
  • 10
  • Check out the top answer(the one which received the bounty) here: http://stackoverflow.com/questions/13402782/show-dialogfragment-with-animation-growing-from-a-point – Veneet Reddy Nov 09 '16 at 13:27
  • not work for DialogFragment. tested before @VeneetReddy – Hamed Nov 09 '16 at 15:41

2 Answers2

0

For animation you have to apply the style in onCreateDialog method. I had the same issue and then I applied the style in 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>
Jaymin Panchal
  • 2,664
  • 2
  • 24
  • 28
0

The reason was that animations on device were disabled.

double-beep
  • 3,889
  • 12
  • 24
  • 35
Hamed
  • 79
  • 10