Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中改变网格子元素的绘制方向,从右到左_Android_Gridview_Android Layout - Fatal编程技术网

如何在Android中改变网格子元素的绘制方向,从右到左

如何在Android中改变网格子元素的绘制方向,从右到左,android,gridview,android-layout,Android,Gridview,Android Layout,我正在尝试使用网格,但我需要将插入子对象的方向从(从左到右)更改为(从右到左)。有没有办法做到这一点,简单的例子会帮助我更多 提前感谢。我想唯一的方法是创建自定义gridview,覆盖onLayout()方法。 看一看 或者您可以反转列表适配器中每一行的项目?类似于3列网格,而不是 [1 2 3][4 5 6][7 8] --> [3 2 1][6 5 4][null 8 7]. (我承认我从未使用过gridview)我写了这个。我想我能解决你的问题 /** Returns in

我正在尝试使用网格,但我需要将插入子对象的方向从(从左到右)更改为(从右到左)。有没有办法做到这一点,简单的例子会帮助我更多


提前感谢。

我想唯一的方法是创建自定义gridview,覆盖onLayout()方法。 看一看

或者您可以反转列表适配器中每一行的项目?类似于3列网格,而不是

[1 2 3][4 5 6][7 8]  -->
[3 2 1][6 5 4][null 8 7].

(我承认我从未使用过gridview)

我写了这个。我想我能解决你的问题

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

        }
/**按步骤返回颠倒的列表。例如,如果我们的列表是{1,2,3,4,5,6,
*7,8,9}步骤是3,倒排列表是:{3,2,1,6,5,4,9,8,7}
*/
公共静态ArrayList反转(列表源,整数步){
List inversed=new ArrayList();
对于(int i=0;i
我面临同样的问题,但最终使用重置数组解决了 此处仅更改u r
第3列

 ArrayList<String> tb_ith_sections_list = new ArrayList<String>;
tb_ith_sections_list = dbhelper.getArrayList();
        int sectionCount = tb_ith_sections_list.size();
                if(sectionCount > 0){
                    int rowCount =sectionCount/4;
                    int colCount ;
                    if(sectionCount > 4){
                         colCount=4;
                    }else{
                         colCount = sectionCount;
                    }
                    if(colCount>sectionCount){
                        colCount=sectionCount;
                    }
                    int k=colCount;
                    int m=0;
                    for(int j=0;j<rowCount;j++){
                        m=(j*colCount);
                        k=m+colCount;
                        if(k>sectionCount){
                            k=(sectionCount-(j*colCount));
                        }
                        for(int i=m;i<k;i++){
                            TB_IVN_SECTIONS tb_Temp=new TB_IVN_SECTIONS();
                            TB_IVN_SECTIONS tb_ithFirst=tb_ith_sections_list.get(i);
                            TB_IVN_SECTIONS tb_ithSecond= tb_ith_sections_list.get(k-1);
                            tb_Temp=tb_ithFirst;
                            tb_ith_sections_list.set(i, tb_ithSecond);
                            tb_ith_sections_list.set(k-1,tb_ithFirst);
                            k--;
                        }               
                    }
ArrayList tb_ith_sections_list=new ArrayList;
tb_ith_sections_list=dbhelper.getArrayList();
int sectionCount=tb_ith_sections_list.size();
如果(截面计数>0){
int rowCount=sectionCount/4;
int colCount;
如果(截面计数>4){
colCount=4;
}否则{
colCount=sectionCount;
}
if(colCount>sectionCount){
colCount=sectionCount;
}
int k=colCount;
int m=0;
对于(int j=0;jsc计数){
k=(sectionCount-(j*colCount));
}
对于(int i=m;i