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
There are few insects whose names are often unkno...
“Many of the problems facing humanity are not sim...
The biggest advantage of Android phones is that th...
[[415572]] This article is reprinted from the WeC...
Evolution Classroom "Douyin Good Product Sal...
Some people say that content monetization is noth...
In 2017, a dark horse, Qutoutiao, emerged in the ...
Author: Zhang Fengguang, epidemiology expert, cha...
The Passenger Car New Four Modernizations Index, ...
The prices on Taobao’s daily specials are very ch...
Qiuqiu Comics e-commerce: Comics Gravitational Cu...
Ideal Auto announced its delivery data for Januar...
The app.json file in the root directory of the mi...
Before we knew it, the Shenzhou 14 crew has been ...
□ Feng Weimin Recently, the international geologi...