圆形堆栈视图

时间:2013-07-01 13:45:20

标签: android

所以使用this我尝试将ciruclar listview的逻辑应用于创建循环堆栈视图。似乎stackview尝试一次加载它的所有内容,不像listview,所以我不断得到一个内存不足的异常。是这样的吗?如果是这样有办法进行循环堆栈查看?这是我到目前为止所使用的,它正被应用于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;
    }
}

1 个答案:

答案 0 :(得分:3)

原来在stackview上有一个名为android:loopViews的属性,它完全符合我的要求。