在gridview中使用右到左的方向 [英] Using right to left direction in gridview

查看:80
本文介绍了在gridview中使用右到左的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



例如:

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

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

GridView如下所示:

 $ 1 $ 3 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 

但我想这样展示它:

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


解决方案

通过Dmytro Danylyk的建议,我使用这个功能并解决了我的问题。

  / **返回倒数列表。例如,如果我们的列表是{1,2,3,4,5,6,
* 7,8,9}并且步骤是3倒排列表是这样的:{3,2,1,6,5, 4,9,8,7}
* /
public static< E>的ArrayList< E - 代替;反转(列表< E>源,int步骤){
列表< E> inverted = new ArrayList< E>(); (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));
}
}
}

//
//当(source.size()%step)不是0时,这是最后一次列表。添加未添加的源的最后部分
//。
//
int余数= source.size()%step; ((余数)!= 0){
for(int j = source.size() - 1,count = 0; count <(remaining); j--,count ++){
inverted.add(source.get(j));
}
}

return(ArrayList< E>)倒置;

}


I want to use right to left direction in gridview. By default gridview shows contents left to right.

For example:

If I have this array and I want to specify 3 column for it:

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

GridView shows it like this:

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

but I want to show it like this:

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

解决方案

By the suggestion of "Dmytro Danylyk" i use this function and solve my problem.

   /** 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;

        }

这篇关于在gridview中使用右到左的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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