重复造轮子:弹性阻尼View和下拉放大View

本文介绍了如何在Android应用中实现滑动后具有弹性阻尼回弹效果和下拉放大视图。作者分享了自己的实现过程,并提供了示例布局代码和GitHub项目的链接。

最近发现好多APP的页面多多少少都上了点滑动后回弹的效果,虽然网上已经有不少实现,但找了几个并不怎么合适。于是自己改造记录下,后面应该用得上,这是我实现好的效果:

1、阻尼效果View2、下拉放大View
ZDampingNestedScrollView.gifZoomNestScrollView.gif

使用

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" 即可。

示例: act_zoom_view.xml

<?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>

代码地址:https://github.com/humoo/WidgetSample

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值