因此,使用它我尝试将 ciruclar listview 的逻辑应用于创建循环 stackview。与 listview 不同,stackview 似乎一次尝试加载其所有内容,因此我不断收到内存不足异常。是这样吗?如果是这样有没有办法做循环stackview?这是我到目前为止所拥有的,它正在应用于堆栈视图。
public class PlayerCardAdapter extends ArrayAdapter<Player>{
private List<Player> items;
private Context ctx;
public static final int HALF_MAX_VALUE = Integer.MAX_VALUE/2;
public final int MIDDLE;
public PlayerCardAdapter(Context context, int textViewResourceId,
List<Player> objects) {
super(context, textViewResourceId, objects);
this.items = objects;
this.ctx = context;
MIDDLE = HALF_MAX_VALUE - HALF_MAX_VALUE % items.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.player_card, null);
}
Player m = this.getItem(position);
if (m != null) {
TextView playerName = (TextView) v.findViewById(R.id.playerColor);
GradientDrawable playerShape;
playerShape = (GradientDrawable) playerName.getBackground();
playerShape.setColor(m.getPlayerColor());
playerShape.setStroke(10, m.getOffsetColor());
playerName.setText(m.getPlayerName());
if(m.isDark()){
playerName.setTextColor(Color.WHITE);
}
else{
playerName.setTextColor(Color.BLACK);
}
}
return v;
}
@Override
public int getCount(){
return Integer.MAX_VALUE;
}
@Override
public Player getItem(int position){
return items.get(Math.abs(position % items.size()));
}
public List<Player> getItems() {
return items;
}
public void setItems(List<Player> items) {
this.items = items;
}
}