首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从顶部排列GridView项

从顶部排列GridView项
EN

Stack Overflow用户
提问于 2019-12-18 02:17:01
回答 3查看 57关注 0票数 0

我下载了一个源码并进入那个源码

使用一个GridView

我希望这些项目是自上而下的

但是顺序是自下而上的。

我该怎么办呢

从上到下排列

就像下面的照片

这些是我的代码

代码语言:javascript
复制
<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"/>

代码语言:javascript
复制
public class SquaresAdapters extends BaseAdapter {
private Activity mActivity;
private List<Square> mList;

public SquaresAdapters(Activity activity, List<Square> squares) {
    mActivity = activity;
    mList = squares;
}
@Override
public Object getItem(int position) {
    return null;
}
@Override
public int getCount() {
    return mList.size();
}
@Override
public long getItemId(int position) {
    return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View choice;
    LayoutInflater inflater = mActivity.getLayoutInflater();
    if (convertView == null) {
        choice = inflater.inflate(R.layout.square_view, parent, false);
        TextView textChoice = (TextView) choice;
        if (!mList.get(position).getState()) {
            textChoice.setBackground(AppCompatResources.getDrawable(mActivity, R.drawable.background_squares_with_empty_state));
        } else {
            textChoice.setBackground(AppCompatResources.getDrawable(mActivity, R.drawable.background_squares_with_populated_state));
        }
        textChoice.setText(mList.get(position).getLetter());
        if (mList.get(position).getTextColor().equals("black")) {
            textChoice.setTextColor(ContextCompat.getColor(mActivity, R.color.black_dark));
        } else {
            textChoice.setTextColor(ContextCompat.getColor(mActivity, R.color.green16));
        }
    } else {
        choice = convertView;
    }
    return choice;
}
public void setSquaresList(List<Square> list) {
    mList = list;
}

}

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-12-19 05:54:38

如果你使用现成的源代码,并且你有这个问题,可能是代码中的某个地方,这将使项目反向显示

搜索并查找该代码并对其进行编辑或删除

代码,如

Collections.reverse(mList);

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

票数 0
EN

Stack Overflow用户

发布于 2019-12-18 02:24:28

反转传递给适配器的数据,如下所示

代码语言:javascript
复制
public SquaresAdapters(Activity activity, List<Square> squares) {
  mActivity = activity;
  mList = squares;
  Collections.reverse(mList);// this will reverse the list
}

如果您在创建适配器后设置数据,也可以在此处反转

代码语言:javascript
复制
public void setSquaresList(List<Square> list) {
   mList = list;
   Collections.reverse(mList);
   notifyDataSetChanged();
}

将getItem更改为以下内容

代码语言:javascript
复制
@Override
public Object getItem(int position) {
    return mList.get(position);
}
票数 0
EN

Stack Overflow用户

发布于 2019-12-18 02:29:44

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

代码语言:javascript
复制
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));
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59379964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档