Giter Site home page Giter Site logo

Comments (5)

thundeGG avatar thundeGG commented on July 25, 2024

大佬,有demo吗

from vegalayoutmanager.

salmanit avatar salmanit commented on July 25, 2024

@7hunder
上边代码也差不多了,你继承LinearLayoutManager 就完事了。也没啥demo吧,recyclerView该咋用咋用,就是layoutManager用这个就行了。
`import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View

class LayoutManagerScaleFirst:LinearLayoutManager{
constructor(context: Context?) : super(context)
constructor(context: Context?, orientation: Int, reverseLayout: Boolean) : super(context, orientation, reverseLayout)

private var oldChild0:View?=null;
private val scaleMinFactor=0.7f //from 0 to 1
override fun scrollVerticallyBy(dy: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State?): Int {
    val result=super.scrollVerticallyBy(dy, recycler, state)
    if(childCount>1){
        val child1=getChildAt(1)
        val child0=getChildAt(0)
        if(oldChild0!=null&&oldChild0!=child0){
            resetChild(oldChild0!!)
        }
        oldChild0=child0
        val scale=scaleMinFactor+(1-scaleMinFactor)*(child1.top)/getDecoratedMeasuredHeight(child1)
        println("scrollVerticallyBy====${scale}==childCount=${childCount}===${getChildAt(0).height}====${getChildAt(1).top}")
        viewAnimate(child0,scale,getDecoratedMeasuredHeight(child1)-child1.top.toFloat())
        if(scale<scaleMinFactor){
            resetChild(child0)
            removeAndRecycleView(child0,recycler)
        }
    }
    return  result
}
private fun resetChild(child:View){
    viewAnimate(child,1f,0f)
}

private fun viewAnimate(child: View,factor:Float,transY:Float){
    child.apply {
        pivotX=this.width/2f
        pivotY=this.height/1f
        scaleX=factor;
        scaleY=factor;
        alpha=factor;
        translationY=transY
    }
}

}`

from vegalayoutmanager.

thundeGG avatar thundeGG commented on July 25, 2024

感谢大佬

from vegalayoutmanager.

thundeGG avatar thundeGG commented on July 25, 2024

加上margin或者padding后能看到顶上缩小的view

from vegalayoutmanager.

salmanit avatar salmanit commented on July 25, 2024

不知道你说的啥样子,上下margin用decoration就行,左右的margin应该没啥影响吧,我这里是滑动的效果图,没看出有啥问题。 或者你具体说下,给谁添加margin?另外我就是个菜鸟。
https://www.jianshu.com/p/42f9997e3ce0

from vegalayoutmanager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.