仿高德地图首页效果,简单代码实现
Posted BigSweetee
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了仿高德地图首页效果,简单代码实现相关的知识,希望对你有一定的参考价值。
2021/11/10日高德的首页效果是这样的
然后我的效果
关键代码
behavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback()
override fun onStateChanged(bottomSheet: View, newState: Int)
//3 STATE_EXPANDED 4 STATE_COLLAPSED 5 STATE_HIDDEN
Log.d("Swt", "newState" + newState)
if (newState == BottomSheetBehavior.STATE_SETTLING)
if (lastNewState == BottomSheetBehavior.STATE_EXPANDED)
if (mSlideOffset < 1f)
behavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
lastNewState = BottomSheetBehavior.STATE_HALF_EXPANDED
return
if (lastNewState == BottomSheetBehavior.STATE_HALF_EXPANDED)
if (mSlideOffset > halfExpandedRatio)
behavior.state = BottomSheetBehavior.STATE_EXPANDED
lastNewState = BottomSheetBehavior.STATE_EXPANDED
if (mSlideOffset < halfExpandedRatio)
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
lastNewState = BottomSheetBehavior.STATE_COLLAPSED
return
if (lastNewState == BottomSheetBehavior.STATE_COLLAPSED && mSlideOffset > peekRatio)
behavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
lastNewState = BottomSheetBehavior.STATE_HALF_EXPANDED
return
override fun onSlide(bottomSheet: View, slideOffset: Float)
Log.d("Swt", "slideOffset" + slideOffset)
mSlideOffset = slideOffset
)
代码地址
https://github.com/BigSweet/GDHome
有用的话点个start,自己研究写的,网上一般都是自定义的behavior,我发现bottomsheet自己就有三级状态直接用一个变量控制实现了
以上是关于仿高德地图首页效果,简单代码实现的主要内容,如果未能解决你的问题,请参考以下文章
Android Studio 仿首页美团切换城市(ListView)+数据库帮助类SQLiteOpenHelper+LetterView(字母排序)