Android Development (31) animation demonstration and android animation demonstration
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:
Public class MainActivity extends Activity {Button button1; @ Overrideprotected 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 () {@ Overridepublic void onClick (View v) {// TODO Auto-generated method stub AlertDialog dialog = new AlertDialog. builder (MainActivity. this ). setTitle ("title "). setMessage ("message "). create ();Window window = dialog. getWindow (); window. setGravity (Gravity. BOTTOM); // you can set the dialog display position window here. setWindowAnimations (R. style. mystyle); // Add an animationDialog. 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
Android Development Forum
Learning IT is not an urgent task. You must be patient. I have studied at Huaxia 3G 3G 3G 3G 3G. The teachers there have development experience in this area. Having Real online applications, you can pay for it after you get employment _.
Android development background
I guess I want to set the layout attribute to wrapcontent and then setBackground, or write the layout width and height to dp Based on the image attribute. Haha, let's see him change again ?! Of course, it is unrealistic for your small image to adapt to various resolutions on the screen, and it is difficult to achieve satisfactory background image effects. If it is a large image, you have no choice, it is estimated that other controls will be sacrificed. In the initial stage, fill the background with a monochrome color. RGB is easy to adjust, is it hard to make a BitMap object in the main program to adjust the image size based on displaymanager?