Android dropdown refresh full parse, teach you how to achieve a drop down refresh function in one minute

Source: Internet
Author: User
Tags xmlns

Recently, the project needs to use the ListView to refresh the function, a start to figure out the easy, online directly to find a ready-made, but try a number of versions of the Internet after the Drop-down refresh found that the effect is not ideal. Some of them are incomplete or bug-prone because they are too complex to use, and the perfect one is never found. So I also gave up the idea of finding ready-made code on the Internet, I spent my time writing a very simple drop-down refresh implementation plan, now take out and share with you. It is believed that after reading this article, everyone can introduce a drop-down refresh function in one minute of their project.

First, let's talk about the implementation principle. The solution we'll take here is to use a combination view to customize a layout to inherit from the LinearLayout, and then add the dropdown and ListView two child elements to the layout, and let the two child elements be vertically arranged. When initializing, let the drop head offset up the screen so that we can see only ListView. The ListView Touch event is then monitored, and if the current ListView has been scrolled to the top and the fingers are still pulling down, then the Drop-down head is displayed, the drop is refreshed, and the dropdown head is hidden. Schematic diagram is as follows:

So let's do it now. To implement, create a new project named Pulltorefreshtest, first in the project to define a drop-head layout file Pull_to_refresh.xml, the code looks like this:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http:// Schemas.android.com/tools "android:id=" @+id/pull_to_refresh_head "android:layout_width=" Fill_parent "Android:l" ayout_height= "60dip" > <linearlayout android:layout_width= "200dip" Android:layout_heigh t= "60dip" android:layout_centerinparent= "true" android:orientation= "Horizontal" > < Relativelayout android:layout_width= "0dip" android:layout_height= "60dip" android:layou t_weight= "3" > <imageview android:id= "@+id/arrow" Android: Layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:layout_centerinpa
                Rent= "true" android:src= "@drawable/arrow"/> <progressbar
      Android:id= "@+id/progress_bar"          Android:layout_width= "30dip" android:layout_height= "30dip" Android:layout_center  
      
        Inparent= "true" android:visibility= "Gone"/> </RelativeLayout> <linearlayout android:layout_width= "0dip" android:layout_height= "60dip" an
                droid:layout_weight= "android:orientation=" "Vertical" > <textview Android:id= "@+id/description" android:layout_width= "fill_parent" android:layout_height= "0
                Dip "android:layout_weight=" 1 "android:gravity=" Center_horizontal|bottom " android:text= "@string/pull_to_refresh"/> <textview android:id= "@+id/updated_at "Android:layout_width=" fill_parent "android:layout_height=" 0dip "Android:
      layout_weight= "1"          Android:gravity= "Center_horizontal|top" android:text= "@string/updated_at"/> </l Inearlayout> </LinearLayout> </RelativeLayout>

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.