Android Development ListView Head disappears the page navigation bar's gradient appears and hides _android

Source: Internet
Author: User
Tags visibility

1.Fragment page XML layout:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http:// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "xmlns:ptr=" Http://schemas.android.com/apk/res-auto "tools:context=". Fragment.home.HomeStoreFragment "> < Com.handmark.pulltorefresh.library.PullToRefreshListView android:id= "@+id/lv_home_store_list" Android:layout_ Width= "Match_parent" android:layout_height= "match_parent" ptr:ptrdrawable= "@drawable/default_ptr_flip" PTR: ptranimationstyle= "Flip"/> <!--top search bar--> <linearlayout android:id= "@+id/ll_top_search" Android:layout_
Width= "Match_parent" android:layout_height= "60DP" android:background= "@color/zuti" android:visibility= "Invisible" > <linearlayout android:layout_width= "match_parent" android:layout_height= "Match_parent" Android:layout_ marginleft= "15DP" android:layout_marginright= "15DP" android:layout_margintop= "8DP" android:layout_marginbottom= " 8DP "Android:background= "@drawable/shape_edit_cornor" android:gravity= "center" > <imageview android:id= "@+id/iv_search_icon" Android : layout_width= "30DP" android:layout_height= "30DP" android:src= "@drawable/icon_navbar_search" Android:layout_ marginright= "5DP"/> <edittext android:id= "@+id/et_store_search" android:layout_width= "Wrap_content" Android: layout_height= "Wrap_content" android:hint= "enter merchant or commodity name" android:textcolorhint= "@color/shenhui" android:background= "@ Null "/> </LinearLayout> </LinearLayout> </RelativeLayout>

2. Main code:

Private Boolean Isflingscroll;
Private View Headview;
Private Pulltorefreshlistview Lvhomestore; Initview () {Lvhomestore = (Pulltorefreshlistview) View.findviewbyid (r.id.lv_home_store_list); LvHomeStore.setMode (
PullToRefreshBase.Mode.BOTH);
ListView ListView = Lvhomestore.getrefreshableview ();
Headview = Initheadview (); Abslistview.layoutparams layoutparams = new Abslistview.layoutparams (AbsListView.LayoutParams.MATCH_PARENT,
AbsListView.LayoutParams.WRAP_CONTENT);//This sentence should be added to Headview.setlayoutparams (Layoutparams);
Listview.addheaderview (Headview);
Lvhomestore.setadapter (adapter);
Lvhomestore.setonscrolllistener (this); @Override public void onscrollstatechanged (Abslistview view, int scrollstate) {if (scrollstate = = scroll_state_fling) {
The finger leaves the handset interface, the ListView still is sliding isflingscroll = true;
Or else if (scrollstate = = Scroll_state_touch_scroll) {//the situation where the finger scrolls on the interface isflingscroll = FALSE;}} @Override public void Onscroll (Abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) {showsearchbarshow ();} private void Showsearchbarshow () {int headbottomtoparenttop = Headview.getheight () + HEADVIEW.G
Ettop ();
LOG.D ("Homestore", "Headview.getheight ():" + headview.getheight ());
LOG.D ("Homestore", "Headview.gettop ():" + headview.gettop ());
LOG.D ("Homestore", "Headbottomtoparenttop:" + headbottomtoparenttop);
if (!isflingscroll) {///the position of the finger sliding in the interface int height = layoutsearch.getheight ();
LOG.D ("Homestore", "Height:" + height); if (Headbottomtoparenttop > height) {layoutsearch.setvisibility (view.invisible);} else if (Headbottomtoparenttop &
lt;= height) {//Slow sliding, this part of the code works fine, fast sliding, the data inside can not keep pace.
float alpha = (height-headbottomtoparenttop) * 1f/height;
LOG.D ("Homestore", "Alpha:" + alpha);
Layoutsearch.setalpha (Alpha);
Layoutsearch.setvisibility (view.visible);
if (!headview.isshown ()) {//solve the problem of fast sliding, the upper part of the code does not work properly.
Layoutsearch.setalpha (1);
Layoutsearch.setvisibility (view.visible); } else {//fingers left, ListView is still sliding, the general situation is the list of fast sliding, this situation directly set the navigation bar visibility if (!headview.isshown ()) {if (!)Layoutsearch.isshown ()) {layoutsearch.setvisibility (view.visible); Layoutsearch.setalpha (1);}}
else {if (Layoutsearch.isshown ()) {layoutsearch.setvisibility (view.invisible);}}} }

The above is a small set to introduce the Android development of the head of the ListView disappeared page navigation bar gradient appears and hidden, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

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.