Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So when I made the sample app to demo this I had to do 2 things. </p> <p>First, was edit the <code>onDraw(Canvas)</code> on my custom view. This could be any view, I make it a TextView for simplicity. This allows me to push the view over based on an equation.</p> <pre><code>public class MyView extends TextView { private static final int MAX_INDENT = 300; private static final String TAG = MyView.class.getSimpleName(); public MyView(Context context) { super(context); } public void onDraw(Canvas canvas){ canvas.save(); float indent = getIndent(getY()); canvas.translate(indent, 0); super.onDraw(canvas); canvas.restore(); } public float getIndent(float distance){ float x_vertex = MAX_INDENT; DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics(); float y_vertex = displayMetrics.heightPixels / 2 / displayMetrics.density; double a = ( 0 - x_vertex ) / ( Math.pow(( 0 - y_vertex), 2) ) ; float indent = (float) (a * Math.pow((distance - y_vertex), 2) + x_vertex); return indent; } } </code></pre> <p>The second thing I had to do was to Override the ListView class, make it implement OnScrollListener and call <code>setOnScrollListener(this);</code>. Now I am able to scroll through the list, it follows the equation that I put in the view.</p> <pre><code>public class HalfCircleListView extends ListView implements AbsListView.OnScrollListener { public HalfCircleListView(Context context) { super(context); setOnScrollListener(this); } @Override public void onScrollStateChanged(AbsListView absListView, int i) { //Ignored } @Override public void onScroll(AbsListView absListView, int i, int i2, int i3) { absListView.invalidateViews(); } } </code></pre> <p>You can download the full source from my <a href="https://gist.github.com/ethankhall/5518832" rel="noreferrer">Gist</a>.</p> <p><strong>Initial State</strong> <img src="https://i.stack.imgur.com/xeklV.png" alt="Initial State of the View"> <strong>Scrolled State</strong> <img src="https://i.stack.imgur.com/UvzFr.png" alt="Scrolled to the bottom"></p> <p>As you can see my math is a little off... I use a parabola vs a circle, so that will have to be changed. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload