读书人

GridView示范2(自动增长)

发布时间: 2012-06-27 14:20:09 作者: rapoo

GridView示例2(自动增长)

第一步:布局xml

?第二步:定义图片的个数以及其他

public int getRED_BALL_COUNT() {return RED_BALL_COUNT;}public void setRED_BALL_COUNT(int rED_BALL_COUNT) {RED_BALL_COUNT = rED_BALL_COUNT;}// 自定义适配器class BallAdapter extends BaseAdapter {// 上下文环境Context context;Drawable drawable;// 构造方法public BallAdapter(Context context, Drawable drawable) {super();this.context = context;this.drawable = drawable;}// 获得数量public int getCount() {// TODO Auto-generated method stubif (drawable == tv_gray_draw) {return getRED_BALL_COUNT();} else {return 0;}}// 获得当前选项public Object getItem(int item) {return item;}// 获得当前选项IDpublic long getItemId(int id) {return id;}public View getView(int position, View convertView, ViewGroup parent) {TextView tv_ball;if (convertView == null) {// 实例化ImageView对象tv_ball = new TextView(context);tv_ball.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));} else {tv_ball = (TextView) convertView;}tv_ball.setGravity(Gravity.CENTER);tv_ball.setTextColor(Color.BLACK);TextPaint tp = tv_ball.getPaint();tp.setFakeBoldText(true);tv_ball.setBackgroundDrawable(drawable);tv_ball.setText((position + 1) + "");return tv_ball;}}

?

?

读书人网 >软件架构设计

热点推荐