Android imitation Netease client top navigation bar effect

Recently, I just wrote an animation effect of the navigation bar on the home page of Netease client. Now I share it for you to learn. Let me talk about the core principle of this effect. The following is the rendering:

The first is the layout, which I got after decompiling from Netease client. After reading, you should understand that the layout file is as follows:

The horizontal Scrollview is used here to realize the effect of moving left and right when the number of navigation bars exceeds the screen. The two imagebuttons are used to realize the operation of scrolling left and right. A frame layout is used in horizontalscrollview. As we all know, the frame layout is an overlay layout, so the ImageView in it will be one layer below the LinearLayout layout. This ImageView realizes the dynamic background effect. The LinearLayout contains textview, which is dynamically added in the background program.

How can I dynamically move the image view to the selected textview position after I click a textview? Here, we need to add ontouchevent () time for each textview and listen for action_ Down time, that is, when the finger is pressed, we start a translateanimation translation animation, and then move the ImageView to the textview position at the end of the animation. Moving the position of textview is realized by dynamically adjusting the layout of textview.

The following is the implementation code:

At the beginning of this method, I get the coordinate position of the textview pressed by my finger, and lastx is the position pressed by my finger last time. I make a judgment here to determine the moving direction, and then add an animation monitoring event to the animation. At the end of the animation, I dynamically move the ImageView to the new coordinate position. setFillEnabled(true); The main function here is to avoid the random jump of animation. I don't know the specific reason here, but everything is normal after the animation is set.

The following is the code of the ontouchevent event of textview:

In this code, I mainly realized the font color change of textview. You should understand it. There's nothing to say.

Finally, the horizontalscrollview control is implemented to move left and right through the left and right imagebuttons of the stand-alone. This is to call the smoothscrollto (x, y) method of horizontalscrollview in the onclick event of the imagebutton, which passes in new coordinates. The following is the implementation code:

The following is the code for dynamically adding textview:

The following is the ID of the dynamically generated control defined in the ids.xml file:

Source download: Android imitation Netease client top navigation bar

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>