Pop up the dialog from the bottom of the page, gradually go down when it disappears

Source: Internet
Author: User

I want to achieve an effect, and it will pop up gradually from the bottom up. As shown in:

1. When the Show button is clicked, a dialog box pops up slowly from the bottom.

2. When the dialog is disabled, the slowly moving of the dialog disappears to the bottom. Very smooth.

 

 

Implementation Method:

Write the following code in the activity:

123456789101112131415161718192021222324252627 public class MainActivity extends Activity {    Button button1;     @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                 button1 = (Button)findViewById(R.id.button1);        button1.setOnClickListener(mOnClickListener);    }     OnClickListener mOnClickListener = new View.OnClickListener(){         @Override        public void onClick(View v) {            //TODO Auto-generated method stub               AlertDialog dialog = new AlertDialog.Builder(MainActivity.this                    .setTitle("title").setMessage("message").create();              <span style="color: #ff0000;"><strong>Window window = dialog.getWindow();              window.setGravity(Gravity.BOTTOM);  // You can set the dialog display position here.            window.setWindowAnimations(R.style.mystyle);  // Add an animation </strong> </span>            dialog.show();         }             }; }

Prepare a style resource file and createMystyle

  <style name="mystyle" parent="android:Animation">        <item name="@android:windowEnterAnimation">@anim/dialog_enter</item>        <item name="@android:windowExitAnimation">@anim/dialog_exit</item></style>

Two animations are used in this mystyle:

Dialog_enter.xml

<?xml version="1.0" encoding="utf-8"?>    <set xmlns:android="http://schemas.android.com/apk/res/android" >        <translate            android:duration="600"            android:fromYDelta="100%p" />    </set>

Dialog_exit.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="600"        android:toYDelta="100%p" /></set>

So far.

 

Code explanation:

1. Set an animation style for Windows where dialog is located.

2. This style specifies the animation (dialog_enter) and the animation (dialog_exit) that the form (Windows) enters)

3. In the input animation dialog_enter, A translate change is written to specify the position starting from the 100% position of its parent container. The 100% position of its parent container is outside the screen and cannot be seen. This is the start point. If no end point is specified, the position (to be displayed) of the end point is displayed by default ).

4. Similarly, dialog_exit defines the animation when leaving. The animation does not specify the start position, and the end position is the 100% position of its parent container, so that it gradually disappears out of the screen.


Android: toydelta = "100% P" 100% indicates the 100% position of its parent container

If you write

Android: toydelta = "100%" indicates the starting position of 100%.

Refer:

Http://www.linuxidc.com/Linux/2012-04/59153.htm

Http://blog.csdn.net/ztp800201/article/details/7387668

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.