Android 从顶部排列GridView项目

Android 从顶部排列GridView项目,android,gridview,Android,Gridview,我下载了一个源代码,并输入到该源代码中 使用了一个GridView 我希望项目是自上而下的 但顺序是从下到上 我该怎么办 从上到下排列 喜欢下面的照片吗 这是我的密码 <GridView android:layout_width="match_parent" android:layout_height="130dp" android:stretchMode="columnWidth" andr

我下载了一个源代码,并输入到该源代码中

使用了一个GridView

我希望项目是自上而下的

但顺序是从下到上

我该怎么办

从上到下排列

喜欢下面的照片吗

这是我的密码

<GridView
            android:layout_width="match_parent"
            android:layout_height="130dp"
            android:stretchMode="columnWidth"
            android:numColumns="6"
            android:layoutDirection="rtl"
            android:id="@+id/grid_view_item_details_1"/>

公共类SquaresAdapter扩展BaseAdapter{
私人活动能力;
私人名单;
公共广场适配器(活动、列表广场){
活动性=活动性;
mList=正方形;
}
@凌驾
公共对象getItem(int位置){
返回null;
}
@凌驾
public int getCount(){
返回mList.size();
}
@凌驾
公共长getItemId(int位置){
返回0;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图选择;
LayoutInflater充气机=mActivity.getLayoutInflater();
if(convertView==null){
选项=充气机。充气(R.layout.square_视图,父视图,false);
TextView textChoice=(TextView)选项;
如果(!mList.get(position.getState()){
textChoice.setBackground(AppCompatResources.getDrawable(mActivity,R.drawable.background,带空状态的方块);
}否则{
textChoice.setBackground(AppCompatResources.getDrawable(mActivity,R.drawable.background,带有填充状态的方块);
}
setText(mList.get(position.getLetter());
if(mList.get(position.getTextColor().equals(“black”)){
setTextColor(ContextCompat.getColor(mActivity,R.color.black_-dark));
}否则{
setTextColor(ContextCompat.getColor(mActivity,R.color.green16));
}
}否则{
选择=转换视图;
}
回报选择;
}
公共无效设置方框列表(列表){
mList=列表;
}

}

反向传输到适配器的数据,如

public SquaresAdapters(Activity activity, List<Square> squares) {
  mActivity = activity;
  mList = squares;
  Collections.reverse(mList);// this will reverse the list
}

老实说,这是一个愚蠢的解决方案,但它会给你一个想法:

public SquaresAdapters(Activity activity, List<Square> squares) {
  mActivity = activity;
  mList = new ArrayList<>();
  for(int i = 3; i < 6; i++) {
     mList.add(squares.get(i));
  }
  for(int i = 0; i < 3; i++) {
     mList.add(squares.get(i));
  }
}
public squaresdapters(活动、列表方格){
活动性=活动性;
mList=新的ArrayList();
对于(int i=3;i<6;i++){
mList.add(squares.get(i));
}
对于(int i=0;i<3;i++){
mList.add(squares.get(i));
}
}

如果您使用ready source,并且遇到此问题 可能在代码的某个地方,这将使项目以相反的方式显示

搜索并找到该代码,然后编辑或删除它

代码如

Collections.reverse(mList)

for(int i=list.size();i>0;i--)


Etc

你为什么不重新安排你的mList的内容呢?Yunus Kulyyev你解释得更多,但如果你逆转,他将得到123456而不是321654他使用的是
android:layoutDirection=“rtl”
我想这会正常工作,但我们没有看到。是的,那么这应该行了fine@lkhgfj您得到的输出是什么?
public void setSquaresList(List<Square> list) {
   mList = list;
   Collections.reverse(mList);
   notifyDataSetChanged();
}
@Override
public Object getItem(int position) {
    return mList.get(position);
}
public SquaresAdapters(Activity activity, List<Square> squares) {
  mActivity = activity;
  mList = new ArrayList<>();
  for(int i = 3; i < 6; i++) {
     mList.add(squares.get(i));
  }
  for(int i = 0; i < 3; i++) {
     mList.add(squares.get(i));
  }
}