Today I learned about animation. The content of the reference book is very limited. I feel that it is too simple. There are two or three pages in total, and the code accounts for most of them .. As a result, many tangled problems are encountered .. However, it may be a lack of knowledge about game development (because everything is learned every time .. I have read the reference books systematically .. Can only be self-defeating ..), This may lead to some incomprehension and delay of a lot of time. After learning it, I found it very easy to add an animation ~ In the future, snacks should be used for Android applications. In addition to functions, the use of PS and animation will provide a better user experience, which is the responsibility of every female programmer ~ Again .. No aesthetics .. It's terrible ..
Well, it's okay. Let's summarize the problems encountered in this experiment ~ It should be very helpful for beginners ~ It is estimated that I will encounter the same problem ~ (I don't have to spend time laughing at me ..) I have checked a lot of online materials .. Most of them are the same. If you do not elaborate on them, bugs always try to get out of them with your imagination .. Let's get down to the truth ~
PS: I used an XML document to add an animation ~ I personally prefer this separation method ~ It feels clear ~ Is the embodiment of low coupling... Right... (Soft tree is easy to learn ..)
1. This function is used to load the animation. The loadanimation (this, R. anim. Second); the R. anim cannot be found .. Later I found that I used to create the XML file of the animation in the layout folder .. Create an anim under Res and put the xml configuration file of the animation here ~
By the way, attach the key code for animation implementation in Java code ~
second = (ImageView) findViewById(R.id.second);secondAnimation = AnimationUtils.loadAnimation(this, R.anim.second); second.startAnimation(secondAnimation);
2. As we all know, the hour-hand minute-hand second-hand timing may overlap. At the beginning, I wanted to initialize it to 12 o'clock, but I couldn't tune it in the layout file and could not cover it. After thinking about layers, I found the nested layout code when looking for relevant information. This is the first time I learned that layout nesting can overlap .. The layout will be more flexible in the future ~ I use the nested relative layout in the relative layout.
3. The second hand can be moved, but it is a twist and a twist .. Khan .. It makes me laugh and cry .. The centers must be determined using transport Tx and transport ty, but the explanation of this attribute (The starting position of the animation relative to the X and Y coordinates of the object.. And all the materials are the same .. Hence ~ I decided to find a regular way to observe .. I knew that I had already found a regular pattern. In fact, it was a coordinate representation of the center of rotation. The top left corner is 0%. The key here is the control of the entire screen. At least this is my program .. At the beginning, I understood that, compared with the second-hand position, setting X to 0% and Y to 100% would be very strange ..
Attach the code ~
<? XML version = "1.0" encoding = "UTF-8"?> <Set xmlns: Android = "http://schemas.android.com/apk/res/android"> <rotateandroid: fromdegrees = "0" Android: todegrees = "+ 360" Android: Duration = "60000" Android: very Tx = "68%" // a little bit of adjustment of the tangle... Android: equalty = "63%" Android: repeatcount = "-1"/> // This is set to an infinite loop (of course, the XML comment is not like this ~) </Set>
4. Constant speed rotation is a funny problem .. Because a child who has not tried it will certainly not call it a problem .. Android's nickname is "uniform speed" by default .. I don't know .. He is so intelligent .. The pointer is clearly accelerated and slowed down first, and the middle is estimated to be at a uniform speed. However, after a lap, there will be a small pause. I checked the information and found that there are also people with the same problem .. It is said that the XML document cannot be modified directly, because the accelerators in interpolator do not have a uniform speed, so you need to add the following sentence to the Java code:
LinearInterpolator lir = new LinearInterpolator(); secondAnimation.setInterpolator(lir);
And start again ~
In general, the clock is still relatively simple, and the hourly minute-hand second-hand thinking is almost the same, that is, to change the duration time, there is also the value of running Tx, Y, this value does not know what a good way, I guess it's based on experience. I tried it a little bit and it took a lot of time .. I feel that the latest programming is always physical... Last shown in the figure ~ This time, I didn't have much time to spend on PS. The key network speed was too slow, so I was not in the mood .. None of the tutorials can be viewed .. The entire dial is added with text as a background image, which is P from a real table. It is also a little bit of a copy of the seal .. Alas .. Everything is fine-grained .. It is estimated that you are too watery .. You can only use a stupid way to adjust it a little bit... So the interface is rough this time .. PS should be enhanced ~