Search code examples
androidanimationdialogfragment

Animation With DialogFragment Android


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


Solution

  • The reason was that animations on device were disabled.