CoordinatorLayout 和 AppBarLayout 实现的局部点击按钮实现滑动某一个固定的距离
生活随笔
收集整理的這篇文章主要介紹了
CoordinatorLayout 和 AppBarLayout 实现的局部点击按钮实现滑动某一个固定的距离
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
實(shí)現(xiàn)的效果如下:
如果需要的只是折疊效果 可以看這遍文章點(diǎn)擊跳轉(zhuǎn)!!!!!!!!!!!!!!!!!!!!
具體代碼如下
findViewById(R.id.tv).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {CoordinatorLayout.Behavior behavior =((CoordinatorLayout.LayoutParams) appbarlayout.getLayoutParams()).getBehavior();if (behavior instanceof AppBarLayout.Behavior) {AppBarLayout.Behavior appBarLayoutBehavior = (AppBarLayout.Behavior) behavior;int hight = appbarlayout.getHeight();// 滑動 計(jì)算的高度appBarLayoutBehavior.setTopAndBottomOffset(-hight);}}});findViewById(R.id.text).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {CoordinatorLayout.Behavior behavior =((CoordinatorLayout.LayoutParams) appbarlayout.getLayoutParams()).getBehavior();if (behavior instanceof AppBarLayout.Behavior) {AppBarLayout.Behavior appBarLayoutBehavior = (AppBarLayout.Behavior) behavior;//快熟滑動到頂部appBarLayoutBehavior.setTopAndBottomOffset(0);}}});
這里? appbarlayout是AppBarLayout 的id
<com.google.android.material.appbar.AppBarLayoutandroid:id="@+id/appbarlayout"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@android:color/holo_red_dark"app:elevation="0dp">
總結(jié)
以上是生活随笔為你收集整理的CoordinatorLayout 和 AppBarLayout 实现的局部点击按钮实现滑动某一个固定的距离的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 好听的舞蹈室名字大全
- 下一篇: java.lang.NullPointe