【问题标题】:How to change direction of drawing children of grid to Right_To_Left in Android如何在Android中将网格子项的绘制方向更改为从右到左
【发布时间】:2010-12-04 13:24:45
【问题描述】:

我正在尝试使用网格,但我需要将插入子项的方向从(从左到右)更改为(从右到左)。有什么办法吗,简单的例子会帮助我更多。

提前致谢。

【问题讨论】:

    标签: android gridview android-layout


    【解决方案1】:

    这是我写的。我想解决你的问题

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

    【讨论】:

      【解决方案2】:

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

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

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

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

      【讨论】:

        【解决方案3】:

        我遇到了同样的问题,但最终使用重置数组解决了 这里只改变你column no = 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--;
                                }               
                            }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-07-01
          • 2018-06-23
          • 1970-01-01
          • 1970-01-01
          • 2020-02-07
          • 1970-01-01
          相关资源
          最近更新 更多