In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to achieve animation in xml, the article introduces in great detail, has a certain reference value, interested friends must read it!
1. Selector
Selector in Android is mainly used to change the default background of ListView and Button controls.
1. Create a mylist_view.xml file
First, create a new drawable folder under the res directory, and then create a new mylist_view.xml in the new drawable folder. The directory structure is: res/drawable/mylist_view.xml.
two。 Edit mylist_view.xml files according to specific requirements
After creating a new mylist_view.xml file, without adding any attributes, its internal code structure is as follows:
The following can be defined internally as the desired style according to the project requirements. The main attributes are as follows:
3. Referencing mylist_view.xml files
There are three ways to reference the file you just created:
(1) add the following attribute code to ListView
Android:listSelector= "@ drawable/mylist_view"
(2) add the following attribute code to the item interface of ListView
Android:background= "@ drawable/mylist_view"
(3) using JAVA code to write directly
Drawable drawable = getResources () .getDrawable (R.drawable.mylist_view)
ListView.setSelector (drawable)
To prevent the list from being blocked, you need to add the following attribute code to the ListView
Android:cacheColorHint= "@ android:color/transparent"
Property description:
Android:state_selected selected
Android:state_focused gains focus
Android:state_pressed Click
Android:state_enabled sets whether to respond to events, which refers to all events
two。 Write animation in XML
Animation can also be placed in the XML file, so that the maintainability of the program is improved. The steps to write an animation in XML are as follows
1. Create a new folder called anim under the res folder
two。 Create a xml file, and first add the set tag, and change the tag as follows
3. Add a rotate,alpha,scale or translate tag to the tag
4. Use AnimationUtils in the code to load the xml file and generate the Animation object
Alpha animation
Animation a=AnimationUtils.loadAnimation (this, R.anim.alpha); iv.startAnimation (a)
Scale animation
Rotate animation
Translate animation
Here I will focus on android:pivotX and android:pivotY and android:fromXDelta,android:toXDelta.
Android:pivotX= "50" uses absolute coordinates
Android:pivotX= "50%" relative to himself
Android:pivotX= "50% p" relative to parent control
How are these animations called?
Call in styles.xml:
@ style/AnimationActivity true @ anim/translate @ anim/rotate @ anim/close_enter @ anim/close_exit
Note: create a new anim directory under the / res directory, and all the Translate.xml,Scale.xml above are created under this folder.
3 > Interpolator-defines the rate at which the animation changes
① AccelerateDecelerateInterpolator:
The rate changes slowly at the beginning and end of the animation and accelerates in the middle.
② AccelaerateInterPolotor:
The rate changes slowly at the beginning of the animation, and then starts to accelerate.
③ CycleInterpolator:
The animation loop plays a specific number of times at a rate along the sinusoidal curve
④ DecelerateInterpolator:
The speed is slow at the end of the animation.
⑤ LinearInterpolator:
The animation moves at a uniform speed
Define Interpolator in the xml file
Android:interpolator= "@ android:anim/accelerate_interpolator"
Android:shareInterpolator= "true"
So that all Animation share an Interpolator.
Use the code settings in the code as follows
Anim.setInterpolator (new AccelerateInterpolator ())
If you pass true into one AnimationSet of new, all Animation share Interpolator.
The above is all the contents of the article "how to achieve Animation in xml". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.