我下载了一个源码并进入那个源码
使用一个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"/>和
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;
}}
发布于 2019-12-19 05:54:38
如果你使用现成的源代码,并且你有这个问题,可能是代码中的某个地方,这将使项目反向显示
搜索并查找该代码并对其进行编辑或删除
代码,如
Collections.reverse(mList);
和
for (int i = list.size(); i > 0; i--)
等
发布于 2019-12-18 02:24:28
反转传递给适配器的数据,如下所示
public SquaresAdapters(Activity activity, List<Square> squares) {
mActivity = activity;
mList = squares;
Collections.reverse(mList);// this will reverse the list
}如果您在创建适配器后设置数据,也可以在此处反转
public void setSquaresList(List<Square> list) {
mList = list;
Collections.reverse(mList);
notifyDataSetChanged();
}将getItem更改为以下内容
@Override
public Object getItem(int position) {
return mList.get(position);
}发布于 2019-12-18 02:29:44
老实说,这是一个愚蠢的解决方案,但它会给你一个想法:
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));
}
}https://stackoverflow.com/questions/59379964
复制相似问题