Android:具有重叠行的垂直ListView [英] Android: Vertical ListView with overlapped rows

查看:179
本文介绍了Android:具有重叠行的垂直ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在android 1.6或2中创建这样的listview(因为renderscript,只能在3或更高版本中运行,但我需要列表才能处理几乎所有的机器人):

How to create listview like this in android 1.6 or 2 (because of renderscript, which works only in 3 or later, but I need list to work on almost all androids):

推荐答案

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

I used Camera.setTranslate(x, 0, z) in drawChild, where changed x position for rotation virtualization and z for overlaping. Then there was problem with overlapping, because last item was on top and first on bottom layer. So, in onCreate() method called this.setChildrenDrawingOrderEnabled(true) and overriden protected int getChildDrawingOrder (int childCount, int i) {} where I could change order for middle and later rows. This idea was given by Renard, who suggested me in other my post about almost same thing here.

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

My getChildDrawingOrder(int, int) implementation to get overlapping I need:

@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;

}

我希望这篇文章将来会帮助某人

I hope this post will help someone in future

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

Screenshot is actually almost the same as I mentioned in my question. I used alpha, so overlayed items is a little bit see-through:

这篇关于Android:具有重叠行的垂直ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆