The Android status bar background is initially transparent and restores the background color with the slide
Source: Internet
Author: User
<span id="Label3"></p><p><p>Now some applications, the status bar is initially fully transparent, and when the user declines, the status bar transparency is gradually restored, see</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p><br></p></p><p><p>This effect is not difficult to achieve, the head of the ListView is set as a picture, the ListView implements the Onscrolllistener event, which can be achieved when the ListView falls down, and the important code is as Follows:</p></p><p>@Override<br>public void onscroll (abslistview listView, int firstvisibleitem,<br>int visibleitemcount, int Totalitemcount) {<br>if (firstvisibleitem = = 0) {<br>Get Header Layout<br>View view = Listview.getchildat (0);<br>If (view! = Null) {<br>Gets the inverse number of the top position of the header layout now<br>int top =-view.gettop ();<br>Gets the height of the header layout<br>int headerheight = View.getheight ();<br>LOG.I ("info", "firstvisibleitem" + firstvisibleitem + ", top:"<br>+ Top + ", headerheight:" + headerheight);<br>When this condition is met, it is the head layout at the top of the Xlistview first control, only this time we adjust the transparency<br>If (top <= headerheight && top >= 0) {<br>Gets the percentage of the head layout height of the current position<br>float f = (float) top/(float) headerheight;<br>Rl_title.getbackground (). setalpha ((int) (f * 255));<br>Notifies the title bar to refresh the display<br>Rl_title.invalidate ();<br>}<br>}<br>} else if (firstvisibleitem > 0) {<br>Rl_title.setbackgroundcolor (color.argb (255, 0, 00, 0));<br>Rl_title.getbackground (). Setalpha (255);<br>} else {<br>Rl_title.getbackground (). Setalpha (0);<br>}<br><br>}</p><p><p><br></p></p><p><p>In fact, the calculation of the ListView drop Distance. Transparency changes as the ListView Slides. When head has slipped, the status bar restores the defined Color.</p></p><p><p><br></p></p><p><p>Full code:</p></p><p><p>http://blog.csdn.net/bisubisu/article/details/47835359<br></p></p><p><p><br></p></p><p><p><br></p></p>This function reference address: http://www.94cto.com/index/Article/content/id/69842.html<p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>The Android status bar background is initially transparent and restores the background color with the slide</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service