Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Animation to DialogFragment in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 5.98k
    Comment on it

    Hi,

    Here I am adding sliding animation to DialogFragment

    First I am adding animation xml in res/anim folder. Then creating custom style that add to the particular fragmentdialogs's onStart() method.

    slidestart.xml

    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate android:duration="1000" android:fromydelta="100%p" android:toydelta="0">
    </translate></set>

    slideend.xml

    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate android:duration="1000" android:fromydelta="0" android:toydelta="100%p">
    </translate></set>

    Then create custom style in style folder

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

    Defining custom style in onStart() method.

    public class myDialogFragment extends DialogFragment {
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                    Bundle savedInstanceState) {
                View rootView = inflater.inflate(R.layout.custom_message_dialog, container,
                        false);

    //Inflated custom xml , can do whatever we require. return rootView; } @Override public void onStart() { super.onStart(); getDialog().getWindow().setWindowAnimations( R.style.dialog&#95;slide&#95;animation); } }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: