Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android 中实现ListView滑动隐藏标题栏的代码大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

布局中listview要覆盖标题

 int mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();
//滑动监听
showHidetitleBar(true);@H_197_4@
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;
   }
  });@H_197_4@
 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,mtitlePage.getTranslationY(),0);
   mAnimatorContent = ObjectAnimator.ofFloat(standby_lv,standby_lv.getTranslationY(),getresources().getDimension(R.dimen.title_height));
  } else {
   mAnimatortitle = ObjectAnimator.ofFloat(mtitle,-mtitle.getHeight());
   mAnimatortitlePage = ObjectAnimator.ofFloat(mtitlePage,-mtitlePage.getHeight());
   mAnimatorContent = ObjectAnimator.ofFloat(standby_lv,0);
  }
  mAnimatortitle.start();
  mAnimatortitlePage.start();
  mAnimatorContent.start();
 }@H_197_4@

dimen.xml文件

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

以上所述是小编给大家介绍的Android ListView滑动隐藏标题栏的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持

大佬总结

以上是大佬教程为你收集整理的Android 中实现ListView滑动隐藏标题栏的代码全部内容,希望文章能够帮你解决Android 中实现ListView滑动隐藏标题栏的代码所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。