通知ListView控件(上半圈的项目) [英] Circular ListView (Items on Half Circle)
问题描述
我试图做一个圆形的ListView与列表项安排在半圈。它应该是这个样子:
I'm Trying to make a Circular ListView with List Items arranged on Half Circle. it should look something like this:
有一个<一个href="http://stackoverflow.com/questions/13024503/move-items-in-half-circle-just-like-an-endless-listview">related帖子但它被关闭。
我在我自己的自定义通知ListView和它工作正常,但我的问题是,我不能安排列表项半圆的方式,因为它显示在图像上。我试了好东西,但它是没有用的,我不知道该怎么做。
I made my own Circular Custom ListView and it works fine but my Problem is that i can't arrange List Items Half Circle way as it is shown on the image. I tried several things but it was useless, I don't know how to do it.
推荐答案
所以,当我做了示例应用程序来演示这个我必须做两件事情。
So when I made the sample app to demo this I had to do 2 things.
首先,是编辑的OnDraw(画布)
在我的自定义视图。这可能是任何看法,我让一个TextView的简单性。这让我推的景色根据一个方程式。
First, was edit the onDraw(Canvas)
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.
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;
}
}
第二件事情我必须做的是重写的ListView类,使其实现OnScrollListener并调用 setOnScrollListener(本);
。现在我能在列表中滚动,接下去我把视图中的公式。
The second thing I had to do was to Override the ListView class, make it implement OnScrollListener and call setOnScrollListener(this);
. Now I am able to scroll through the list, it follows the equation that I put in the view.
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();
}
}
您可以从我的吉斯特的完整源代码。
You can download the full source from my Gist.
初始状态 滚动州
Initial State Scrolled State
正如你可以看到我的数学是有点过......我用一个抛物线VS了一圈,这样就必须改变。
As you can see my math is a little off... I use a parabola vs a circle, so that will have to be changed.
这篇关于通知ListView控件(上半圈的项目)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!