Android Animation 6 Q 6 Answer

Source: Internet
Author: User

What do 1.view animations need to be aware of?

Answer: The view animation itself is relatively simple. Http://www.cnblogs.com/punkisnotdead/p/5179115.html look at the fifth question of this article can be.

2. How do I add animation to the appearance of viewgroup elements?

Answer: Take the ListView as an example.

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <layoutanimationxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:delay= "0.5"4 Android:animationorder= "normal"5 android:animation= "@anim/viewanim"6     >7 </layoutanimation>
View Code
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Setxmlns:android= "Http://schemas.android.com/apk/res/android"3 android:duration= "+">4 5     <AlphaAndroid:fromalpha= "0.0"6 Android:toalpha= "1.0"></Alpha>7     <TranslateAndroid:fromxdelta= "$"8 Android:toxdelta= "0"></Translate>9 Ten </Set>
View Code
1 < ListView 2         Android:id = "@+id/lv" 3         android:layout_width= "Match_parent"4        android:layout_height = "Match_parent" 5         android:layoutanimation= "@anim/lv_anim"></ListView >
View Code

Look at the effect:

3. How do I set the switch effect for activity and fragment?

Answer: Activity:

1 <?xml version= "1.0" encoding= "Utf-8"?>2 <set xmlns:android= "http://schemas.android.com /apk/res/android "3     android:duration=" >4     <alpha android:fromalpha= "0.0 " 5         android:toalpha= "1.0" ></alpha>6 </set>
View Code
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Setxmlns:android= "Http://schemas.android.com/apk/res/android"3 android:duration= "+">4     <AlphaAndroid:fromalpha= "1.0"5 Android:toalpha= "0.0"></Alpha>6 </Set>
View Code
1  Intent intent=New Intent (mainactivity.  this, otheractivity. class ); 2                 startactivity (intent); 3                 Overridependingtransition (R.anim.enter_anim,r.anim.exit_anim);
View Code

Effect:

Fragment almost is to use Compatibility Pack, Setcustomaniamtions can.

4. What are the criteria for using attribute animations?

A: The Setabc method must be provided if the property animation is performed relative to the property ABC. If the animation does not provide an initial value, there are also GETABC methods available

Because the system to take the initial value of ABC, do not get the initial value must be an error.

In addition, the SETABC method must be able to change the actual UI of the view, so that people can feel the UI changes, otherwise the property animation can run but because there is no effect,

And I can't see it.

5. Use property animations for the button's Width property, why not? What are the solutions?

For:

1   @android. View.remotableviewmethod2      Public void setwidth (int  pixels) {3         mmaxwidth = Mminwidth = pixels; 4         Mmaxwidthmode = Mminwidthmode = PIXELS; 5 6         requestlayout (); 7         invalidate (); 8     }
View Code

You see, the button obviously has a setwidth method, but this method does not actually modify the layout property of the view, so of course it is invalid.

WORKAROUND: You can use a class that indirectly provides a get set method.

1  Static classWrapper2     {3         PrivateView Mtarget;4 5          PublicWrapper (View target)6         {7mtarget=Target;8         }9 Ten          Public intgetwidth () One         { A             returnmtarget.getlayoutparams (). width; -         } -  the          Public voidSetWidth (intwidth) -         { -Mtarget.getlayoutparams (). width=width; - mtarget.requestlayout (); +         } -  +}
View Code
1bt=(Button) Findviewbyid (R.ID.IV);2         FinalWrapper wrapper=NewWrapper (BT);3Bt.setonclicklistener (NewView.onclicklistener () {4 @Override5              Public voidOnClick (View v) {6 7Objectanimator.ofint (Wrapper, "width",). Setduration (5000). Start ();8}
View Code

You can also use Valueanimator to monitor the animation process and then modify the property values of the view itself in the process.

1  Public voidOnClick (View v) {2 3Valueanimator Valueanimator=valueanimator.ofint (1,100);4Valueanimator.addupdatelistener (NewValueanimator.animatorupdatelistener () {5                     //for the sake of simplicity, we can change linearly.6                     PrivateIntevaluator mevaluator=Newintevaluator ();7 @Override8                      Public voidonanimationupdate (valueanimator animation) {9                         intCurrentvalue=(Integer) animation.getanimatedvalue ();Ten                         floatfraction=animation.getanimatedfraction (); OneBt.getlayoutparams (). Width=mevaluator.evaluate (Fraction,bt.getlayoutparams (). width,500); A bt.requestlayout (); -                     } -                 }); theValueanimator.setduration (). Start ();
View Code

Finally look at the effect:

6. What are some important points to note when using animations?

A: 1. Frame animation try not to use, because the picture is too large when the Oom

2. If your animation is infinite loop, such as the property animation inside, then you have to quit the activity to remember to stop the animation or memory leak

3.view animation again, the UI layer of the view, which is the user-perceived level, has changed, and the nature of the actual UI has not changed. If an exception occurs after using the View animation, you can try calling Clearanimation to return to normal.

4. Use the DP px for the animation.

5. Note that 3.0 of the API is compatible, but the personal advice is not to support the device under 4.0 for 2016 years.

6. Turning on hardware acceleration is good for animation efficiency.

Android Animation 6 Q 6 Answer

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.