欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 中實(shí)現(xiàn)ListView滑動(dòng)隱藏標(biāo)題欄的代碼

 更新時(shí)間:2017年01月18日 14:41:26   作者:Wo來給你講故事  
本文通過實(shí)例代碼給大家分享了android listview滑動(dòng)隱藏標(biāo)題欄的方法,代碼簡(jiǎn)單易懂,需要的朋友參考下

布局中l(wèi)istview要覆蓋標(biāo)題欄

 int mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();
//滑動(dòng)監(jiān)聽
showHideTitleBar(true);
ListView standby_lv = (ListView) findViewById(R.id.standby_lv);
standby_lv.setOnTouchListener(new View.OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
      mFirstY = event.getY();
      break;
     case MotionEvent.ACTION_MOVE:
      mCurrentY = event.getY();
      if (mCurrentY - mFirstY > mTouchSlop) {
       // 下滑 顯示titleBar
       showHideTitleBar(true);
      } else if (mFirstY - mCurrentY > mTouchSlop) {
       // 上滑 隱藏titleBar
       showHideTitleBar(false);
      }
      break;
     case MotionEvent.ACTION_UP:
      break;
    }
    return false;
   }
  });
 private Animator mAnimatorTitle;
 private Animator mAnimatorTitlePage;
 private Animator mAnimatorContent;
 private void showHideTitleBar(boolean tag) {
  if (mAnimatorTitle != null && mAnimatorTitle.isRunning()) {
   mAnimatorTitle.cancel();
  }
  if (mAnimatorTitlePage != null && mAnimatorTitlePage.isRunning()) {
   mAnimatorTitlePage.cancel();
  }
  if (mAnimatorContent != null && mAnimatorContent.isRunning()) {
   mAnimatorContent.cancel();
  }
  if (tag) {
   mAnimatorTitle = ObjectAnimator.ofFloat(mTitle, "translationY", mTitle.getTranslationY(), 0);
   mAnimatorTitlePage = ObjectAnimator.ofFloat(mTitlePage, "translationY", mTitlePage.getTranslationY(), 0);
   mAnimatorContent = ObjectAnimator.ofFloat(standby_lv, "translationY", standby_lv.getTranslationY(), getResources().getDimension(R.dimen.title_height));
  } else {
   mAnimatorTitle = ObjectAnimator.ofFloat(mTitle, "translationY", mTitle.getTranslationY(), -mTitle.getHeight());
   mAnimatorTitlePage = ObjectAnimator.ofFloat(mTitlePage, "translationY", mTitlePage.getTranslationY(), -mTitlePage.getHeight());
   mAnimatorContent = ObjectAnimator.ofFloat(standby_lv, "translationY", standby_lv.getTranslationY(), 0);
  }
  mAnimatorTitle.start();
  mAnimatorTitlePage.start();
  mAnimatorContent.start();
 }

dimen.xml文件

<dimen name="titlepage_height">45dp</dimen>

以上所述是小編給大家介紹的Android ListView滑動(dòng)隱藏標(biāo)題欄的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論