<?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 James Lee on Medium]]></title>
        <description><![CDATA[Stories by James Lee on Medium]]></description>
        <link>https://medium.com/@jrlee11235?source=rss-b3b16375eab0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WJkAbtQWV9AGwF57vD6dMg.jpeg</url>
            <title>Stories by James Lee on Medium</title>
            <link>https://medium.com/@jrlee11235?source=rss-b3b16375eab0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 02:37:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jrlee11235/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[A simple CenterSliderView for Android]]></title>
            <link>https://medium.com/postmates-blog/a-simple-centersliderview-for-android-4a45e2e9ba5e?source=rss-b3b16375eab0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a45e2e9ba5e</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[android-widget]]></category>
            <category><![CDATA[postmates]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[James Lee]]></dc:creator>
            <pubDate>Thu, 03 May 2018 16:45:27 GMT</pubDate>
            <atom:updated>2018-05-03T16:48:27.928Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kRMwEBQ3godJkEfvhlNX-A.png" /></figure><p>There is a tenuous balance between the practicality of what engineers build and the ideal visuals that designers create for a feature. We hold ourselves to a high standard at Postmates when producing the designs and subsequently making those designs a reality.</p><p>The team was tasked to build a new feature which would streamline the way our merchant partners submit their order estimates. The design request included a slider that would automatically re-center itself after the user had moved to a particular value, while also inflating and deflating the dragger according to the touch event of the user’s finger on the screen. After searching around the standard Android widgets and other open-source draggers or sliders, we came to the conclusion that a widget providing this specific behavior was not readily available. Thus, the CenterSliderView was born.</p><p>Before we get into implementation details, here is a demonstration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MVL2q9NOxnzyUEeHnb3PJA.gif" /><figcaption>Center Slider Demo</figcaption></figure><p>Cool, so how did we achieve this behavior? Well, to start, everything is drawn directly to the canvas — from each of the lines to the dragger to each text.</p><p>Starting with the idle state, all lines are represented by start and end points such that the baseline stretches across the width of the screen and each of the ticks are stored in a list of coordinates that are equidistant from each other. The slider is composed of two AnimatedVectorDrawables, which are displayed depending on the touch and animation states — when pressed, it shows and starts the one which inflates; on release, the one that deflates. In onDraw(Canvas), the view simply calls canvas.drawLine() for each line in the list of line coordinates and invokes Drawable.draw(Canvas) on the proper drawable.</p><p>Moving on to the re-centering animation, we needed to allow the slider to move left and right while recording the total x-distance moved. This distance is used to determine both how far the slider must animate back in order to re-center and the final resting value for the slider. By running on a 16 ms loop (60 fps), we are able to produce a smooth animation after calculating the updated positions throughout the animation’s duration. In each frame, we evaluate the new position of each line and add or remove lines from the drawing list according to if they remain on or off the screen. Instead of changing the positions of all the lines every 16 ms, each line’s x-position is added with a single updated x-translation value for the duration of the animation. Once the animation completes, all the remaining lines can be updated with their final resting x-positions. I can apply a similar principle to the slider’s elements so that the view as a whole feels like it is snapping to the center after the user lifts their finger.</p><p>There’s a lot omitted for the sake of brevity, but hopefully this provides a brief introduction to the implementation of theCenterSliderView. Other topics you might be curious about include constraining the ends of the baseline at the edges of the range, running the slider inflate/deflate and centering animations on the same loop, or using an interpolator for a final design polish.</p><p>Today, we’re happy to declare that this widget is open-sourced and can be found with further documentation and usability details on <a href="https://github.com/postmates/centersliderview-android">GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a45e2e9ba5e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/postmates-blog/a-simple-centersliderview-for-android-4a45e2e9ba5e">A simple CenterSliderView for Android</a> was originally published in <a href="https://medium.com/postmates-blog">Postmates</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>