我使用http://www.codeproject.com/Articles/146145/Android-3D-Carousel創建垂直轉盤視圖的代碼.i可以使用代碼中的下列更改來查看垂直轉盤,但中心項目未正確放置在屏幕中,並且如果列表項目大小增加,直徑向上移動。android 3D垂直轉盤視圖
private void setUpChild(CarouselImageView child, int index, float angleOffset) {
// Ignore any layout parameters for child, use wrap content
addViewInLayout(child, -1 /*index*/, generateDefaultLayoutParams());
child.setSelected(index == mSelectedPosition);
int h;
int w;
if (mInLayout)
{
h = (getMeasuredHeight() - getPaddingBottom()-getPaddingTop())/3;
w = getMeasuredWidth() - getPaddingLeft() - getPaddingRight()/3;
}
else
{
h = (getMeasuredHeight() - getPaddingBottom()-getPaddingTop())/3;
w = getMeasuredWidth() - getPaddingLeft() - getPaddingRight()/3;
}
child.setCurrentAngle(angleOffset);
// modify the diameter.
Calculate3DPosition(child, w*(getAdapter().getCount()/4), angleOffset);
// Measure child
child.measure(w, h);
int childLeft;
// Position vertically based on gravity setting
int childTop = calculateTop(child, true);
childLeft = 0;
child.layout(childLeft, childTop, w, h);
}
變化calculate3position
功能如下
float x = (float) (-diameter/2 * Math.cos(angleOffset) * 0.00001);
float z = diameter/2 * (1.0f - (float)Math.cos(angleOffset));
float y = (float) (diameter/2 * Math.sin(angleOffset)) + diameter/2 - child.getWidth();
child.setX(x);
child.setZ(z);
child.setY(y);
感謝您的答覆,我嘗試了上面的計算,但它無法正常工作:http://i.stack.imgur.com/DDnkw.png – user853341
這對我來說是一個非常令人驚訝的結果。也許我不瞭解該演示的座標系。您是否嘗試添加寬度偏移量?像這樣:float y =(diameter/2.0f * Math.sin(angleOffset))+ diameter/2.0f + child.getHeight()/ 2.0f; – HalR
是的,我試過相同的。如果我做y = y-250,那麼我可以看到中心位置的列表項,但它不會支持多個屏幕分辨率和列表項。 – user853341