Tween animation (four types) and Inter-activity jump Animation

Source: Internet
Author: User

Main. XML is as follows:

<RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="wrap_content"    android:layout_height="wrap_content" >    <ImageView         android:id="@+id/imageView"        android:layout_width="60dip"        android:layout_height="90dip"        android:scaleType="fitXY"        android:layout_marginTop="80dip"        android:src="@drawable/haha"        android:layout_centerHorizontal="true"     />    <LinearLayout         android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="horizontal"        android:layout_below="@id/imageView"        android:layout_marginTop="35dip"    >        <Button             android:id="@+id/alphaButton"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="alpha"               />         <Button             android:id="@+id/scaleButton"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="scale"            android:layout_marginLeft="15dip"        />          <Button             android:id="@+id/rotateButton"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="rotate"            android:layout_marginLeft="15dip"        />           <Button             android:id="@+id/translateButton"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="translate"            android:layout_marginLeft="15dip"        />    </LinearLayout>    <TextView        android:id="@+id/textView"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_marginTop="270dip"        android:text="@string/hello_world"        tools:context=".MainActivity" />    <Button         android:id="@+id/button1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Jump To 1"        android:layout_below="@id/textView"        android:layout_marginTop="20dip"        android:layout_alignParentLeft="true"           />         <Button         android:id="@+id/button2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Jump To 2"        android:layout_below="@id/textView"        android:layout_marginTop="20dip"        android:layout_alignParentRight="true"           /></RelativeLayout>

The secondactivity layout is as follows:

<?xml version="1.0" encoding="utf-8"?><LinearLayout     xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="horizontal" >    <TextView         android:layout_width="120dip"        android:layout_height="wrap_content"        android:text="The second Activity"        android:layout_gravity="center_vertical"        android:layout_marginLeft="120dip"     /></LinearLayout>

Mainactivity is as follows:

Package com. example. testactivityjumpanimation; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. view. animation. animation; import android. view. animation. animationUtils; import android. widget. button; import android. widget. imageView; public class MainActivity extends Activity {private Button button1; private Button button2; private Button alphaButton; private Button scaleButton; private Button rotateButton; private Button translateButton; private Animation animation; private ImageView imageView; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); // Animation 1 button1 = (Button) findViewById (R. id. button1); button1.setOnClickListener (new ButtonClickListener (); // Animation 1 button2 = (Button) findViewById (R. id. button2); button2.setOnClickListener (new ButtonClickListener (); // display the animated ImageView imageView = (ImageView) findViewById (R. id. imageView); // test the four animation buttons alphaButton = (Button) findViewById (R. id. alphaButton); scaleButton = (Button) findViewById (R. id. scaleButton); rotateButton = (Button) findViewById (R. id. rotateButton); translateButton = (Button) findViewById (R. id. translateButton); alphaButton. setOnClickListener (new ButtonClickListener (); scaleButton. setOnClickListener (new ButtonClickListener (); rotateButton. setOnClickListener (new ButtonClickListener (); translateButton. setOnClickListener (new ButtonClickListener ();} private class ButtonClickListener implements OnClickListener {public void onClick (View v) {switch (v. getId () {// animation jump between activities 1 case R. id. button1: Intent intent1 = new Intent (MainActivity. this, SecondActicity. class); startActivity (intent1); // note the parameter explanation: // the first parameter enterAnim // A resource ID of the animation resource to use for the incoming activity. // Use 0 for no animation. // the second parameter exitAnim // A resource ID of the animation resource to use for the outgoing activity. // Use 0 for no animation. // note that this method should be next to startActivity () or finish () and overridePendingTransition (R. anim. in1, R. anim. out1); break; case R. id. button2: Intent intent2 = new Intent (MainActivity. this, SecondActicity. class); startActivity (intent2); overridePendingTransition (R. anim. in2, R. anim. out2); break; // opacity animation case R. id. alphaButton: animation = AnimationUtils. loadAnimation (MainActivity. this, R. anim. alphaanimation); imageView. startAnimation (animation); break; // case R. id. scaleButton: animation = AnimationUtils. loadAnimation (MainActivity. this, R. anim. scaleanimation); imageView. startAnimation (animation); break; // rotating animation case R. id. rotateButton: animation = AnimationUtils. loadAnimation (MainActivity. this, R. anim. rotateanimation); imageView. startAnimation (animation); break; // displacement animation case R. id. translateButton: animation = AnimationUtils. loadAnimation (MainActivity. this, R. anim. translateanimation); imageView. startAnimation (animation); break; default: break ;}}}}

Secondactivity is as follows:

package com.example.testactivityjumpanimation;import android.app.Activity;import android.os.Bundle;public class SecondActicity extends Activity { @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.second);           }}

The following is an animated XML file.

Alphaanimation. XML is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?> <! -- The Alpha value is between 0.0 and 1.0 --> <! -- Invisible when Alpha = 0 --> <! -- Completely visible when Alpha = 1 --> <! -- RepeatCount sets the number of animation repetitions --> <! -- RepeatCount = 1, the animation will be executed twice in total --> <! -- RepeatCount indicates that it must be executed several times after the original execution --> <! -- Android: repeatMode is available in two ways. You can see it after testing --> <! -- Android: fillAfter and android: fillBefore can only be set in set !!! Android: fillAfter = "true" indicates that after the animation ends, the current screen is the effect after the animation ends. android: fillBefore = "true" indicates that after the animation ends, the current screen is the effect before the animation starts --> <! -- Android: startOffset is also set in set for effect --> <! -- Android: interpolator used to control the speed of animation execution --> <set xmlns: android = "http://schemas.android.com/apk/res/android" android: fillBefore = "true"> <alpha android: fromAlpha = "1.0" android: toAlpha = "0.1" android: duration = "10000" android: repeatCount = "1"/> </set>

Scaleanimation. xml is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?> <! -- FromX (Y) Scale and toX (Y) Scale values: --> <! -- 0.0 indicates shrinking to none --> <! -- 1.0 indicates normal non-shrinking --> <! -- If the value is less than 1.0, it indicates shrinking --> <! -- If the value is greater than 1.0, the value is enlarged. --> <! -- Note: --> <! -- Both from and to of X and Y should be set; otherwise, there will be no effect --> <! -- Pivot is the intention of pivot, and the meaning of the central point --> <! -- Relative TX (Y) indicates the starting position of the X and Y coordinates of the animation relative to the object --> <! -- The optional TX (Y) value range is 0% to 100% --> <set xmlns: android = "http://schemas.android.com/apk/res/android"> <scale android: fromXScale = "0.4" android: toXScale = "2.0" android: fromYScale = "0.4" android: toYScale = "2.0" android: Large Tx = "100%" android: Large ty = "50%" android: duration = "3000"/> </set>

Rotateanimation. xml is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?> <! -- Android: fromDegrees indicates the angle of the animation relative to the original object at the beginning --> <! -- Android: toDegrees indicates the angle of rotation relative to the original object at the animation end --> <! -- The angle used here: positive number indicates clockwise rotation --> <! -- The angle used here: a negative number indicates clockwise rotation --> <! -- The following statements are inaccurate --> <! -- From is negative, to is positive, clockwise --> <! -- From is a negative number, to is a negative number, and is rotated counterclockwise --> <! -- From is positive, to is positive, clockwise --> <! -- From is a positive number, to is a negative number, and it is rotated counterclockwise --> <! -- It should be to minus from = result --> <! -- The result is greater than 0 and clockwise --> <! -- The result is less than 0, and it is rotated counterclockwise --> <! -- The same as from and to described above: --> <! -- Positive number indicates clockwise rotation --> <! -- Negative number indicates clockwise rotation --> <! -- Better understanding --> <! -- It should be from minus to = result --> <! -- The result is greater than 0, and it is rotated counterclockwise --> <! -- The result is smaller than 0, and the timing needle is rotated --> <! -- Consistent understanding: Clockwise is negative, clockwise is positive --> <! -- Pivot is the intention of pivot, and the meaning of the central point --> <! -- Distinct TX (Y) indicates the X and Y coordinates of the original object at the beginning of the animation. --> <! -- Optional TX (Y) value range: 0% to 100% --> <set xmlns: android = "http://schemas.android.com/apk/res/android"> <rotate android: fromDegrees = "90" android: toDegrees = "-90" android: Short Tx = "50%" android: Short ty = "50%" android: duration = "4000"/> </set>

Translateanimation. xml is as follows:

<? XML version = "1.0" encoding = "UTF-8"?> <! -- Fromxdelta indicates the difference between X of the animation start point and the current view X coordinate. toxdelta indicates the difference between X of the animation end point and the current view X coordinate. fromydelta indicates the animation start point. the difference between Y and Y in the current view y coordinate toydelta indicates the difference between Y at the starting point of the animation and Y in the current view y coordinate --> <set xmlns: android = "http://schemas.android.com/apk/res/android"> <translate Android: fromxdelta = "100" Android: toxdelta = "0" Android: fromydelta = "30" Android: toydelta = "0" Android: duration = "3000"/> </set>

 

In1.xml is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?> <! -- Act on the upcoming Activity --> <set xmlns: android = "http://schemas.android.com/apk/res/android" android: interpolator = "@ android: anim/decelerate_interpolator"> <scale android: duration = "3000" android: fromXScale = "2.0" android: toXScale = "1.0" android: fromYScale = "2.0" android: toYScale = "1.0" android: required Tx = "50%" android: Required ty = "50%"/> </set>

Out1.xml is as follows:

<? XML version = "1.0" encoding = "UTF-8"?> <! -- Act on the activity that is about to disappear --> <set xmlns: Android = "http://schemas.android.com/apk/res/android" Android: interpolator = "@ Android: anim/decelerate_interpolator" Android: zadjustment = "TOP"> <scale Android: Duration = "5000" Android: fromxscale = "1.0" Android: toxscale = "0.5" Android: fromyscale = "1.0" Android: toyscale = "0.5" Android: rjtx = "50%" Android: 0000ty = "50%"/> <Alpha Android: Duration = "5000" Android: fromalpha = "1.0" Android: toalpha = "0.0"/> </set>

In2.xml is as follows:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <translate        android:fromXDelta="320"        android:toXDelta="0"        android:duration="300"    /></set>

Out2.xml is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?> <! -- Set android: fromXDelta = "0" and android: toXDelta = "0" to prevent black screens when the Activity page jumps. and note: out2 android: duration and in2 in the consistent --> <set xmlns: android = "http://schemas.android.com/apk/res/android"> <translate android: fromXDelta = "0" android: toXDelta = "0" android: duration = "300"/> </set>

 

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.