gpt4 book ai didi

java - Android:具有重叠行的垂直 ListView

转载 作者:搜寻专家 更新时间:2023-10-30 19:45:19 25 4
gpt4 key购买 nike

如何在 android 1.6 或 2 中创建这样的 ListView (因为 renderscript,它只能在 3 或更高版本中工作,但我需要列表才能在几乎所有的 android 上工作):

enter image description here

最佳答案

我在 drawChild 中使用了 Camera.setTranslate(x, 0, z),其中更改了用于旋转虚拟化的 x 位置和用于重叠的 z。然后有重叠的问题,因为最后一个项目在顶层,第一个在底层。因此,在 onCreate() 方法中调用 this.setChildrenDrawingOrderEnabled(true) 并覆盖 protected int getChildDrawingOrder (int childCount, int i) {} 其中我可以更改中间行和后面行的顺序。这个想法是由 Renard 提出的,他在我的其他帖子中就几乎相同的事情向我提出了建议 here .

我需要实现重叠的 getChildDrawingOrder(int, int) 实现:

@Override
protected int getChildDrawingOrder (int childCount, int i) {
int centerChild = 0;
//find center row
if ((childCount % 2) == 0) { //even childCount number
centerChild = childCount / 2; // if childCount 8 (actualy 0 - 7), then 4 and 4-1 = 3 is in centre.
int otherCenterChild = centerChild - 1;
//Which more in center?
View child = this.getChildAt(centerChild);
final int top = child.getTop();
final int bottom = child.getBottom();
//if this row goes through center then this
final int absParentCenterY = getTop() + getHeight() / 2;
//Log.i("even", i + " from " + (childCount - 1) + ", while centerChild = " + centerChild);
if ((top < absParentCenterY) && (bottom > absParentCenterY)) {
//this child is in center line, so it is last
//centerChild is in center, no need to change
} else {
centerChild = otherCenterChild;
}
}
else {//not even - done
centerChild = childCount / 2;
//Log.i("not even", i + " from " + (childCount - 1) + ", while centerChild = " + centerChild);
}

int rez = i;
//find drawIndex by centerChild
if (i > centerChild) {
//below center
rez = (childCount - 1) - i + centerChild;
} else if (i == centerChild) {
//center row
//draw it last
rez = childCount - 1;
} else {
//above center - draw as always
// i < centerChild
rez = i;
}
//Log.i("return", "" + rez);
return rez;

}

我希望这篇文章对以后的人有所帮助

屏幕截图实际上与我在问题中提到的几乎相同。我使用了 alpha,所以叠加的项目有点透明:

enter image description here

关于java - Android:具有重叠行的垂直 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10211835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com