<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shivam Satija on Medium]]></title>
        <description><![CDATA[Stories by Shivam Satija on Medium]]></description>
        <link>https://medium.com/@droidsergeant?source=rss-c4a97860ccfe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FNFp5QYDB2JHLiIFveiZTg.jpeg</url>
            <title>Stories by Shivam Satija on Medium</title>
            <link>https://medium.com/@droidsergeant?source=rss-c4a97860ccfe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 02:03:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@droidsergeant/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hack that RecyclerView!]]></title>
            <link>https://medium.com/mindorks/hack-that-recyclerview-f6b8238e68ec?source=rss-c4a97860ccfe------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6b8238e68ec</guid>
            <category><![CDATA[custom-views]]></category>
            <category><![CDATA[recyclerview]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Shivam Satija]]></dc:creator>
            <pubDate>Thu, 15 Jun 2017 07:46:50 GMT</pubDate>
            <atom:updated>2018-08-16T02:25:01.424Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I installed a new app <a href="https://play.google.com/store/apps/details?id=com.chanel.fashion.public"><strong>Chanel Fashion</strong></a>, not to buy something for my girlfriend but to study its <strong>UI/UX</strong>. The main activity of this application is awesome. I tried to make this by myself, so my solution is illustrated in this post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/1*KDgGPaFDSP_4bYD3FSpklg.gif" /><figcaption>Chanel Fashion</figcaption></figure><blockquote><em>Every problem has a solution. That solution can be optimal, simple, concise or may be wrong.</em></blockquote><p>My solution for this problem is very simple. I have made a custom ViewGroup by extending RecyclerView. And on scroll I’m changing height of its each child according to their position. To be more precise, I have implemented <strong>RecyclerView.OnScrollListener </strong>which has two methods <strong>onScrollStateChanged(</strong>RecyclerView <strong>recyclerView</strong>, int <strong>newState</strong>)<strong> </strong>and <strong>onScrolled(</strong>RecyclerView <strong>recyclerView</strong>, int <strong>dx</strong>, int <strong>dy</strong>).</p><p><strong>onScrollStateChanged()</strong> is invoked when recyclerview’s state is changed and it has two parameters <strong>recyclerView </strong>whos scroll state has changed and <strong>newState </strong>the updated scroll state. One of SCROLL_STATE_IDLE, SCROLL_STATE_DRAGGING or SCROLL_STATE_SETTLING. Now in this method I am calculating the height of view according to the distance of view’s top from the reference point (ie. top of recyclerview). And the code goes as —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06b6726dbce518d62e1c05e0bbbbbbdf/href">https://medium.com/media/06b6726dbce518d62e1c05e0bbbbbbdf/href</a></iframe><p>In <strong>changeHeightAccrodingToScroll(</strong>recyclerView<strong>) </strong>the actual magic is happening. This method is invoked every time <strong>onScrolled() </strong>is called. And the code for this method is —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccead767104f40fadd68e2d7931f5416/href">https://medium.com/media/ccead767104f40fadd68e2d7931f5416/href</a></iframe><p>The top of recyclerView is reference point. If distance of view’s top from reference point is greater than <strong>maxDistance </strong>then its height would be <strong>defaultItemHeight </strong>and if distance is 0 (zero) the view would be of its max height ie. <strong>featuredItemHeight.</strong></p><p>Below diagram is showing how view would look. <strong>featuredItemHeight</strong> is height of top view (featured view) and <strong>defaultItemHeight</strong> is height of rest of the views. In this Recyclerview, each child’s height is ranging from <strong>defaultItemHeight</strong> to <strong>featureItemHeight.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*Oxtv_mhRH0rRk7QRzT1AwQ.jpeg" /></figure><p>And the actual view would look like —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*xv9wGgN27NdNY0MQUsRwwQ.gif" /><figcaption>Yay! Achieved.</figcaption></figure><p>As said above, if <strong>distance</strong> -&gt; 0 then <strong>height</strong> -&gt; <strong>featuredItemHeight </strong>and if <strong>distance</strong> ≥ <strong>maxDistance</strong>, <strong>height</strong> -&gt; <strong>defaultItemHeight</strong></p><p>And if <strong>distance</strong> is between <strong>zero</strong> and <strong>maxDistance</strong> the formula to calculate height will be —</p><pre>/**<br> * <strong>diffHeight</strong> = <strong>featuredItemHeight</strong> - <strong>defaultItemHeight</strong>;<br> */<strong><br></strong>private<strong> </strong>float<strong> height</strong>(float<strong> distance</strong>) {<br>    return<strong> featuredItemHeight </strong>- ((<strong>distance</strong> * (<strong>diffHeight</strong>)) / <strong>maxDistance</strong>);<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*nTQJ4ugY3vhu8gImC_m3jQ.gif" /><figcaption>Isn’t it awesome?</figcaption></figure><p><strong>Like it? Want to use it?</strong> I have made a <strong>open source library</strong> for it. You can see the full source code for reference here : <a href="https://github.com/developer-shivam/FeaturedRecyclerView">https://github.com/developer-shivam/FeaturedRecyclerView</a></p><p><strong>Why library? </strong>because it also has a custom ReyclerView Adapter which can be used to animate properties of childs of recyclerview (like fading).</p><p>Thanks for reading! Be sure to click ❤ below to recommend this article if you found it helpful. It motivates me to write new one.</p><p><em>For more about programming, follow </em><a href="https://medium.com/@droidsergeant"><em>me</em></a><em> and </em><a href="https://blog.mindorks.com/"><em>Mindorks</em></a><em> , so you’ll get notified when I write new posts.</em></p><p><strong>Check out all the top articles at </strong><a href="https://blog.mindorks.com/"><strong>blog.mindorks.com</strong></a></p><p>Also, Let’s become friends on <a href="https://www.facebook.com/developerShivam"><strong>Facebook</strong></a>. Follow me on <a href="https://github.com/developer-shivam"><strong>Github</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6b8238e68ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/hack-that-recyclerview-f6b8238e68ec">Hack that RecyclerView!</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Property Animation — The ValueAnimator]]></title>
            <link>https://medium.com/mindorks/android-property-animation-the-valueanimator-4ca173567cdb?source=rss-c4a97860ccfe------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ca173567cdb</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile]]></category>
            <dc:creator><![CDATA[Shivam Satija]]></dc:creator>
            <pubDate>Sat, 28 Jan 2017 12:52:31 GMT</pubDate>
            <atom:updated>2022-11-25T13:23:37.886Z</atom:updated>
            <content:encoded><![CDATA[<p>ValueAnimator provides a timing engine for running animation which calculates the animated values and set them on the target objects. By ValueAnimator you can animate a view <strong>width</strong>, <strong>height</strong>, update its <strong>x</strong> and <strong>y</strong> coordinates or even can change its <strong>background</strong>.</p><p>It has an interface <strong>ValueAnimator.AnimatorUpdateListener</strong> which is used to receive callbacks on every animation frame.</p><pre>ValueAnimator widthAnimator = ValueAnimator.<em>ofInt</em>(10, 100);<br>widthAnimator.addUpdateListener(<strong>new </strong>ValueAnimator.AnimatorUpdateListener() {<br>    @Override<br>    <strong>public void </strong>onAnimationUpdate(ValueAnimator animation) {<br>        <strong>int </strong>animatedValue = (<strong>int</strong>) animation.getAnimatedValue();<br>        someView.getLayoutParams().<strong>width </strong>= animatedValue;<br>        someView.requestLayout();<br>    }<br>});</pre><p>In above example, I’m updating the width of a view from <strong>10</strong> to <strong>100</strong>. In <strong>onAnimationUpdate()</strong> method the animated value is used to update the width of that view. On calling <strong>requestLayout() </strong>the framework will redraw the view according to updated width value (this method is needed to be called on every change of value otherwise the view will not be redrawn according to updated value and effect would not be seen).</p><p>Besides this simple example, let’s have a look at a little complex one. In this example, I’m going to change <strong>x</strong> and <strong>y</strong> <strong>coordinates</strong> and <strong>size</strong> of the button on click of a <strong>floating action button</strong>. And result is shown below —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*HAlFZY2igY-aum7Hv4zbag.gif" /></figure><p><strong>Using value animator</strong></p><p>Animating a single value with ValueAnimator is straightforward. ValueAnimator provides the static method like ofInt and ofFloat to animate between integer and floating point values.</p><pre>AnimatorSet buttonAnimator = <strong>new </strong>AnimatorSet();<br><br><em>/**<br> * ValueAnimator to update x position of a button<br> */<br></em>ValueAnimator buttonAnimatorX = ValueAnimator.<em>ofFloat</em>(<strong>startPositionX</strong>, <strong>pentagonVertices[position].x</strong>);<br>buttonAnimatorX.addUpdateListener(<strong>new </strong>ValueAnimator.AnimatorUpdateListener() {<br>    @Override<br>    <strong>public void </strong>onAnimationUpdate(ValueAnimator animation) {<br>        button.setX((<strong>float</strong>) animation.getAnimatedValue() - button.getLayoutParams().width / 2);<br>        button.requestLayout();<br>    }<br>});<br>buttonAnimatorX.setDuration(ANIMATION_DURATION);<br><br><em>/**<br> * ValueAnimator to update y position of a button<br> */<br></em>ValueAnimator buttonAnimatorY = ValueAnimator.<em>ofFloat</em>(<strong>startPositionY</strong>, <strong>pentagonVertices[position].y</strong>);<br>buttonAnimatorY.addUpdateListener(<strong>new </strong>ValueAnimator.AnimatorUpdateListener() {<br>    @Override<br>    <strong>public void </strong>onAnimationUpdate(ValueAnimator animation) {<br>        button.setY((<strong>float</strong>) animation.getAnimatedValue());<br>        button.requestLayout();<br>    }<br>});<br>buttonAnimatorY.setDuration(ANIMATION_DURATION);</pre><p>In the above code <strong>startPositionX</strong> &amp; <strong>startPositionY</strong> are the center coordinates of floating action button and <strong>pentagonVertices[position].x, pentagonVertices[position].y </strong>are destination coordinates which are calculated by —</p><pre><em>/**<br> * Calculating the coordinates of vertices of pentagon<br> */<br></em><strong>for </strong>(<strong>int </strong>i = 0; i &lt; NUM_OF_SIDES; i++) {<br>    pentagonVertices[i] = <strong>new </strong>Point((<strong>int</strong>) (radius * Math.<em>cos</em>(rotation + i * 2 * Math.<strong><em>PI </em></strong>/ NUM_OF_SIDES)) + centerX,<br>            (<strong>int</strong>) (radius * Math.<em>sin</em>(rotation + i * 2 * Math.<strong><em>PI </em></strong>/ NUM_OF_SIDES)) + centerY - 100);<br>}</pre><p>So what actually happening is the valueAnimator is animating from <strong>startPositionX</strong> and <strong>startPositionY</strong> to the <strong>pentagonVertices[position].x</strong> and <strong>pentagonVertices[position].x</strong>. And in <strong>onAnimationUpdate()</strong> we are setting these animated value to <strong>x</strong> and <strong>y</strong> of a button.</p><p>Same thing is happening with the <strong>size</strong> of button —</p><pre>ValueAnimator buttonSizeAnimator = ValueAnimator.<em>ofInt</em>(5, width);<br>buttonSizeAnimator.addUpdateListener(<strong>new </strong>ValueAnimator.AnimatorUpdateListener() {<br>    @Override<br>    <strong>public void </strong>onAnimationUpdate(ValueAnimator animation) {<br>        button.getLayoutParams().width = (<strong>int</strong>) animation.getAnimatedValue();<br>        button.getLayoutParams().height = (<strong>int</strong>) animation.getAnimatedValue();<br>        button.requestLayout();<br>    }<br>});<br>buttonSizeAnimator.setDuration(ANIMATION_DURATION);</pre><pre>buttonAnimator.start();</pre><p>It is obvious that we need to update both the x and y coordinates. The naive approach is to create two animations and play them simultaneously, but it is not efficient. We can use <strong>PropertyValuesHolder</strong> to combine multiple values which I’ll demonstrate in my next post.</p><p>By default, ValueAnimator uses non-linear time interpolation, via the <strong>AccelerateDeccelerateInterpolator</strong> class, which accelerates into and decelerates out of an animation. This behavior can be changed by calling <strong>setInterpolator(Time Interpolator)</strong>.</p><p>You can see the full source code here : <a href="https://github.com/developer-shivam/PentagonFloatingActionButton">https://github.com/developer-shivam/PentagonFloatingActionButton</a></p><p>Thanks for reading! Be sure to click ❤ below to recommend this article if you found it helpful. It means a lot to me.</p><p>Also, Let’s become friends on <a href="https://in.linkedin.com/in/developershivam"><strong>Linkedin</strong></a>, <a href="https://github.com/developer-shivam"><strong>Github</strong></a> and <a href="https://www.facebook.com/developerShivam"><strong>Facebook</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ca173567cdb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/android-property-animation-the-valueanimator-4ca173567cdb">Android Property Animation — The ValueAnimator</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>