Skip to content

Instantly share code, notes, and snippets.

@ethankhall
Created May 4, 2013 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethankhall/5518815 to your computer and use it in GitHub Desktop.
Save ethankhall/5518815 to your computer and use it in GitHub Desktop.
Half Circle List View
package io.ehdev.android.example.wheel.layout;
import android.content.Context;
import android.graphics.Canvas;
import android.util.DisplayMetrics;
import android.widget.TextView;
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;
}
}
@sumeetguha
Copy link

Hello,

I was trying to make this circular list horizontally, instead of vertically, but not getting the expected result.
Could you please tell me, what exact changes are required to make the horizontal circular list.

Thanks,
Sumeet Guha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment