Android开发之ListView的head消失页面导航栏的渐变出现和隐藏

Android开发之ListView的head消失页面导航栏的渐变出现和隐藏,第1张

概述1.Fragment页面xml布局:<RelativeLayoutxmlns:android=\"http://schemas.android.com/apk/res/android\"

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消失页面导航栏渐变出现和隐藏,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!

总结

以上是内存溢出为你收集整理的Android开发之ListView的head消失页面导航栏的渐变出现和隐藏全部内容,希望文章能够帮你解决Android开发之ListView的head消失页面导航栏的渐变出现和隐藏所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1147579.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存