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
As October passes, the annual Double 11 event is ...
appendix: 1. At present, the success rate of emer...
Samsung Display recently said that this year'...
What is a hot product? What are the factors that ...
In recent years, with the disappearance of traffi...
We who practice martial arts... um, no, it's ...
The world is really on the brink of danger. When ...
Landing page quality and user matching are two ke...
Inclusion has always been a hot topic of concern ...
Friends who like fishing know that among the vari...
Here, the editor has compiled a wave of common bi...
I saw a very cute metaphor on Zhihu some time ago...
The future is full of uncertainties. What challen...
Event planning and operation is a job that every ...
The Double 11 copywriting has only one purpose, w...