In Android, View mobile control is implemented through ViewHelper. setTranslationY (NineOldAndroids open-source project)
We know that there are many open-source projects that can achieve a lot of good results. A few days ago, I saw a result, and this jar package was also used in the project. I have nothing to do with digging, learning, and learning. (when it comes to digging, the question is, which of the following is the best excavator technology?) How can we achieve good results? What is the significance of a function? Many results,We don't need to re-build the wheel, we just need to assemble the wheel, we can just start drivingNow, you don't have that much time to build wheels. We can choose the wheel we like, open our Lamborghini, and open our Porsche concept car!
Let's take a look at the results first! Mining from open-source projects (NineOldAndroids open-source project)
No nonsense. Let's explain the related functions.
Private View header_logo; private float moveDistanceY = 25; // The initial moving distance of the logo is 10 private float moveDistanceX = 25; // The initial moving distance of the logo is 10 @ Overridepublic void onClick (View v) {switch (v. getId () {case R. id. btn_moveDown: moveDistanceY + = 20; ViewHelper. setTranslationY (header_logo, moveDistanceY); break; case R. id. btn_moveUp: moveDistanceY-= 20; ViewHelper. setTranslationY (header_logo, moveDistanceY); break; case R. id. btn_moveLeft: moveDistanceX-= 20; ViewHelper. setTranslationX (header_logo, moveDistanceX); break; case R. id. btn_moveRight: moveDistanceX + = 20; ViewHelper. setTranslationX (header_logo, moveDistanceX); break; default: break ;}}
Explanation of the ViewHelper. setTranslationY (view, float) function. Here, the view is what you want to move. Which View is what you want to move on the interface? Float refers to the distance you move (assuming that the initial position of the reference coordinate is 0 ). So ViewHelper. setTranslationY (view, 100) is to move the view down (more than the original position) by 100, so what about 120, 130, 140, 150, and?
It is 10, 20, 30, and 40 more than the original location .... SoViewHelper. setTranslationX orViewHelper. setTranslationY can be implemented. Go to the source code. Otherwise, if you don't see the effect, will you scold me. Ga.
To useViewHelperTo reference the jar package. Open-source project jar package
Source code of this project: Click here to make sure that the latest technical article will be updated every week. Every day, efforts should be made to explore technical points (not to start excavators, but to start excavators or go to lanxiang ). Otherwise, do you think I am not angry for so long? It was still hit by a car, but the hospital couldn't get up .....
Zookeeper