introduction Today we are going to study ScrollView, which is divided into horizontal scroll view (HorizontalScrollView) and vertical scroll view (ScrollView). Today we will mainly study the vertical scroll view. I believe that everyone often uses it in development. The function of ScrollView is already very powerful, but it still cannot satisfy our UI designers with wild imagination, so we need to customize it... This article mainly talks about monitoring the sliding of ScrollView to achieve the gradient of the QQ space title bar. Let's take a look at the effect picture first: Okay, let’s get to the point. ScrollView properties you may not know
Set the scroll bar display. None (hide), horizontal (horizontal), vertical (vertical)
Set the scroll bar style and position. Setting value: insideOverlay, insideInset, outsideOverlay, outsideInset
Sets the drawable for the horizontal scroll bar.
Set whether there is a sound effect when clicking or touching
Set the direction of the border gradient when the scroll bar is pulled. None (border color remains unchanged), horizontal (color fades horizontally), vertical (color fades vertically). Refer to the fadingEdgeLength effect diagram android:fadingEdgeLength to set the length of the border gradient
Set the horizontal scroll offset in pixels. This effect can be seen in the GridView.
Set the vertical scroll offset in pixels.
Set whether to always display the vertical scroll bar
Sets the time in milliseconds after which the fade will start. If you are interested in the above properties, you can study them. I won’t go into detail here. Many properties are not commonly used. Let’s talk about the ones we often use. How to monitor the sliding of ScrollView and realize the gradient of the title bar? ScrollView sliding monitoring: Google does not provide us with a method to determine the sliding distance of ScrollView or whether to slide to the bottom or top of the layout, but it does provide an onScrollChanged method:
By viewing the source code comments,
We can know that the parameters of this method are: l: Current horizontal sliding distance t: current vertical sliding distance oldl: previous horizontal sliding distance oldt: previous vertical sliding distance But we cannot call this method. We can rewrite the interface or rewrite ScrollView to expose this method:
Set title gradient Now that the scroll listener is exposed, we should set the title bar to change the transparency of the title bar to achieve a gradual change as the ScrollView slides: Let's take a look at the layout first:
The outermost layer is our custom ScrollView, which wraps a background image and a ListView (ListView is rewritten to not be able to slide), and then there is a TextView on the layout as the title bar. You can also use the layout. Then we need to get the height of the image and set the scroll listener to set the color transparency of the title bar and the transparency of the font color according to the scroll distance.
OK, this achieves the effect you see at the top. In fact, it is not difficult, it’s just that we haven’t implemented it ourselves. I believe that if we do it more ourselves, we can achieve what the UI wants. |
<<: Computing power on data platforms: Which GPUs are better suited for deep learning and databases?
>>: Android image zooming animation is so simple
If we first want to define the personality of the...
When we talk about e-commerce, what will be the f...
Meteor showers have always been a romantic and my...
Show affection and give gifts as they should (the...
A scientific guide to postpartum confinement. Mot...
Baidu has been embroiled in controversy these day...
Chinese ancestors have a long history of using ri...
1. Case Link Official website personal center ent...
I read books on WeChat Reading quite often. It ma...
Leviathan Press: A few years ago, a friend of min...
Recently, the Iranian Ministry of Defense launche...
As the company develops and its market share incr...
Author: Sun Yuhang and Zhou Yixi Medical College ...
A few days ago, I reviewed the relationship betwe...
"Black Hat SEO Optimization" Achao SEO ...