android - 在 gridview 中使用从右到左的方向

标签 android gridview

我想在 gridview 中使用从右到左的方向。默认情况下,gridview 从左到右显示内容。

例如:

如果我有这个数组并且我想为其指定 3 列:

[1, 2, 3, 4, 5, 6, 7, 8, 9]

GridView 显示如下:

[1 2 3]
[4 5 6]
[7 8 9]

但我想这样展示:

[3 2 1]
[6 5 4]
[9 8 7]

最佳答案

根据“Dmytro Danylyk”的建议,我使用此功能并解决了我的问题。

   /** Returns inverted list by step that take. for example if our list is {1, 2, 3, 4, 5, 6,
   * 7 ,8 ,9} and step is 3 inverted list is this: {3, 2, 1, 6, 5, 4, 9, 8, 7}  
   */
       public static <E> ArrayList<E> invert(List<E> source, int step){
            List<E> inverted = new ArrayList<E>();
            for(int i = 0; i < source.size(); i++){
                if((i + 1) % step == 0){
                    for(int j = i, count = 0; count < step; j--, count++){
                        inverted.add(source.get(j));
                    }
                }
            }

            //
            // When (source.size() % step) is not 0 acts.this is for last of list. add last part
            // of the source that wasn't add.
            //
            int remainder = source.size() % step;
            if((remainder) != 0 ){
                for (int j = source.size() - 1, count = 0; count < (remainder); j--, count++) {
                    inverted.add(source.get(j));
                }
            }

            return (ArrayList<E>) inverted;

        }

关于android - 在 gridview 中使用从右到左的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10500967/

相关文章:

android - 无法运行Android OpenCV人脸检测示例

c# - 具有固定标题和全页宽度网格的 Gridview

android - 如何在我的 android gridview 中显示来自互联网的图像并显示完整图像?

android - 焦点在 GridView 布局中

c# - 如何在gridview中将文本转换为货币?

android - 调用 task.execute() 时 ASyncTask 不执行

android - 在 Android 中实现流畅动画的最佳方式

java - 为什么我的应用程序在 AVD 上运行时自动关闭?

java - 在第一个警报对话框之上膨胀第二个警报对话框?

c# - 如何在gridview asp.net中插入单选按钮列