国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android開發之ListView的head消失頁面導航欄的漸變出現和隱藏

2019-12-12 04:31:25
字體:
來源:轉載
供稿:網友

1.Fragment頁面xml布局:

<RelativeLayoutxmlns: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.PullToRefreshListViewandroid: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 搜索欄--><LinearLayoutandroid:id="@+id/ll_top_search"android:layout_width="match_parent"android:layout_height="60dp"android:background="@color/zuti"android:visibility="invisible"><LinearLayoutandroid: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"><ImageViewandroid:id="@+id/iv_search_icon"android:layout_width="30dp"android:layout_height="30dp"android:src="@drawable/icon_navbar_search"android:layout_marginRight="5dp"/><EditTextandroid:id="@+id/et_store_search"android:layout_width="wrap_content"android:layout_height="wrap_content"android:hint="輸入商家或商品名"android:textColorHint="@color/shenhui"android:background="@null"/></LinearLayout></LinearLayout></RelativeLayout>

2.主要代碼:

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);//這句要加上去headView.setLayoutParams(layoutParams);listView.addHeaderView(headView);lvHomeStore.setAdapter(adapter);lvHomeStore.setOnScrollListener(this);}@Overridepublic void onScrollStateChanged(AbsListView view, int scrollState) {if (scrollState == SCROLL_STATE_FLING) {//手指離開手機界面,Listview還在滑動isFlingScroll = true;} else if (scrollState == SCROLL_STATE_TOUCH_SCROLL) {//手指在界面上滾動的情況isFlingScroll = false;}}@Overridepublic void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {showSearchBarShow();}private void showSearchBarShow() {int headBottomToParentTop = headView.getHeight() + headView.getTop();Log.d("homeStore", "headView.getHeight(): " + headView.getHeight());Log.d("homeStore", "headView.getTop(): " + headView.getTop());Log.d("homeStore", "headBottomToParentTop: " + headBottomToParentTop);if (!isFlingScroll) {//手指在界面滑動的情況int height = layoutSearch.getHeight();Log.d("homeStore", "height: " + height);if (headBottomToParentTop > height) {layoutSearch.setVisibility(View.INVISIBLE);} else if (headBottomToParentTop <= height) {//緩慢滑動,這部分代碼工作正常,快速滑動,里面的數據就跟不上節奏了。float alpha = (height - headBottomToParentTop) * 1f / height;Log.d("homeStore", "alpha: " + alpha);layoutSearch.setAlpha(alpha);layoutSearch.setVisibility(View.VISIBLE);}if (!headView.isShown()){//解決快速滑動,上部分代碼不能正常工作的問題。layoutSearch.setAlpha(1);layoutSearch.setVisibility(View.VISIBLE);}} else {//手指離開,listview還在滑動,一般情況是列表快速滑動,這種情況直接設置導航欄的可見性if (!headView.isShown()) {if (!layoutSearch.isShown()){layoutSearch.setVisibility(View.VISIBLE);layoutSearch.setAlpha(1);}} else {if (layoutSearch.isShown()){layoutSearch.setVisibility(View.INVISIBLE);}}}}

以上所述是小編給大家介紹的Android開發之ListView的head消失頁面導航欄的漸變出現和隱藏,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 赤峰市| 吴川市| 宜宾县| 咸宁市| 仪陇县| 仙游县| 遂昌县| 马关县| 正蓝旗| 古田县| 东兴市| 即墨市| 大洼县| 应用必备| 恩平市| 博野县| 九龙坡区| 遂平县| 靖西县| 晋城| 阿坝县| 晋江市| 红河县| 尼勒克县| 西畴县| 永济市| 昌黎县| 准格尔旗| 连江县| 合肥市| 新河县| 东海县| 利川市| 沁源县| 凭祥市| 班戈县| 阜宁县| 新源县| 久治县| 靖西县| 泰顺县|