最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)之ListView的head消失頁面導航欄的漸變出現(xiàn)和隱藏

 更新時間:2016年11月24日 13:55:22   作者:凸尾巴小狼  
這篇文章主要介紹了Android開發(fā)之ListView的head消失頁面導航欄的漸變出現(xiàn)和隱藏的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

1.Fragment頁面xml布局:

<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 搜索欄-->
<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="輸入商家或商品名"
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);
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == SCROLL_STATE_FLING) {//手指離開手機界面,Listview還在滑動
isFlingScroll = true;
} else if (scrollState == SCROLL_STATE_TOUCH_SCROLL) {//手指在界面上滾動的情況
isFlingScroll = false;
}
}
@Override
public 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) {//緩慢滑動,這部分代碼工作正常,快速滑動,里面的數(shù)據(jù)就跟不上節(jié)奏了。
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開發(fā)之ListView的head消失頁面導航欄的漸變出現(xiàn)和隱藏,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

  • Android實現(xiàn)360手機助手底部的動畫菜單

    Android實現(xiàn)360手機助手底部的動畫菜單

    這篇文章給大家分享了利用Android實現(xiàn)360手機助手底部的動畫菜單效果,文中給出了實例代碼,這樣對大家的學習或者理解更有幫助,有需要的朋友們下面來一起看看吧。
    2016-10-10
  • Kotlin?Dispatchers協(xié)程調度器源碼深入分析

    Kotlin?Dispatchers協(xié)程調度器源碼深入分析

    Kotlin協(xié)程不是什么空中閣樓,Kotlin源代碼會被編譯成class字節(jié)碼文件,最終會運行到虛擬機中。所以從本質上講,Kotlin和Java是類似的,都是可以編譯產(chǎn)生class的語言,但最終還是會受到虛擬機的限制,它們的代碼最終會在虛擬機上的某個線程上被執(zhí)行
    2022-11-11
  • android文字描邊功能的實現(xiàn)

    android文字描邊功能的實現(xiàn)

    本文介紹的是android文字描邊功能的實現(xiàn),文字描邊的功能在開發(fā)中還是聽實用的,有需要的可以參考學習
    2016-07-07
  • Android 中解決Viewpage調用notifyDataSetChanged()時界面無刷新的問題

    Android 中解決Viewpage調用notifyDataSetChanged()時界面無刷新的問題

    這篇文章主要介紹了Android 中解決Viewpage調用notifyDataSetChanged()時界面無刷新的問題的相關資料,這里提供相應的解決辦法,需要的朋友可以參考下
    2017-08-08
  • Android開發(fā)應用中Broadcast Receiver組件詳解

    Android開發(fā)應用中Broadcast Receiver組件詳解

    本篇文章主要介紹了Android開發(fā)應用中Broadcast Receiver組件詳解,想要學習的同學可以了解一下。
    2016-11-11
  • Android中巧妙的實現(xiàn)緩存詳解

    Android中巧妙的實現(xiàn)緩存詳解

    采用緩存,可以進一步大大緩解數(shù)據(jù)交互的壓力,有的時候為了快速查詢會被多次調用的數(shù)據(jù),或者構建比較廢時的實例,我們一般使用緩存的方法。無論大型或小型應用,靈活的緩存可以說不僅大大減輕了服務器的壓力,而且因為更快速的用戶體驗而方便了用戶。下面來一起看看吧。
    2016-11-11
  • Android?Notification使用教程詳解

    Android?Notification使用教程詳解

    這篇文章主要介紹了Android?Notification使用,通知的使用的內容還是比較多的,此篇文章將會盡可能詳細的介紹Notification的內容,需要的朋友可以參考下
    2022-07-07
  • 分析Android 11.0Settings源碼之主界面加載

    分析Android 11.0Settings源碼之主界面加載

    這篇文章主要介紹了分析Android 11.0Settings源碼之主界面加載,對Android源碼感興趣的同學,可以著重看一下
    2021-04-04
  • Android N 7.0中報錯:android.os.FileUriExposedException的解決方法

    Android N 7.0中報錯:android.os.FileUriExposedException的解決方法

    這篇文章主要給大家介紹了關于在Android N 7.0中報錯:android.os.FileUriExposedException的解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起看看吧
    2018-05-05
  • Android nativePollOnce函數(shù)解析

    Android nativePollOnce函數(shù)解析

    這篇文章主要介紹了Android nativePollOnce函數(shù)解析的相關資料,幫助大家更好的理解和學習使用Android,感興趣的朋友可以了解下
    2021-03-03

最新評論

麻江县| 县级市| 策勒县| 新竹县| 百色市| 澄迈县| 阿城市| 洪湖市| 沈阳市| 江都市| 秦皇岛市| 卢氏县| 磐石市| 高台县| 饶平县| 东丽区| 沅陵县| 沅陵县| 中江县| 邯郸县| 玉环县| 梁河县| 井陉县| 浮梁县| 娄底市| 潼南县| 称多县| 桓仁| 买车| 麟游县| 阿坝| 航空| 楚雄市| 慈利县| 绥滨县| 大港区| 济源市| 黄山市| 苗栗市| 团风县| 保德县|