Created
May 4, 2013 21:35
-
-
Save ethankhall/5518815 to your computer and use it in GitHub Desktop.
Half Circle List View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.