最近发现好多APP的页面多多少少都上了点滑动后回弹的效果,虽然网上已经有不少实现,但找了几个并不怎么合适。于是自己改造记录下,后面应该用得上,这是我实现好的效果:
1、阻尼效果View | 2、下拉放大View |
---|---|
使用
1、阻尼效果View
在 layout 中,将 ZDampingNestedScrollView
设置为根布局即可。
使用时注意 ZDampingNestedScrollView
继承自 NestedScrollView
,布局中仅支持一个子View布局
示例: act_zdamping_nest_scroll_view.xml
<?xml version="1.0" encoding="utf-8"?>
<com.zhxumao.widget.ZDampingNestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//你的代码
</LinearLayout>
</com.zhxumao.widget.ZDampingNestedScrollView>
2、下拉放大View
① 在 layout 中,将 ZoomNestScrollView 设置为根布局。
② 自己写好需要放大的 view ,设置属性 android:tag="zoom_bg"
即可。
<?xml version="1.0" encoding="utf-8"?>
<com.zhxumao.widget.ZoomNestScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:tag="zoom_bg">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@mipmap/bg2" />
</RelativeLayout>
//你的代码
</LinearLayout>
</com.zhxumao.widget.ZoomNestScrollView>