TA的每日心情 | 开心 2012-3-7 10:15 |
---|
签到天数: 11 天 [LV.3]偶尔看看II
|
01 | import java.util.ArrayList; |
05 | import android.content.Context; |
06 | import android.content.res.Resources; |
07 | import android.graphics.drawable.Drawable; |
08 | import android.util.AttributeSet; |
09 | import android.widget.ImageView; |
10 | import android.widget.LinearLayout; |
12 | public class PageIndicator extends LinearLayout { |
14 | private Context mContext; |
15 | private Drawable mCurrentDrawable; |
16 | private Drawable mNormalDrawable; |
17 | private int mCurrentPage = 0; |
18 | private int mMaxPage = 0 ; |
19 | private ArrayList<ImageView> arrList ; |
20 | public PageIndicator(Context context) { |
22 | this.mContext = context; |
23 | // TODO Auto-generated constructor stub |
26 | public PageIndicator(Context paramContext, AttributeSet paramAttributeSet) |
28 | super(paramContext, paramAttributeSet); |
29 | this.mContext = paramContext; |
30 | loadDefaultDrawable(); |
33 | private void loadDefaultDrawable() |
35 | Resources localResources = this.mContext.getResources(); |
36 | this.mNormalDrawable = localResources.getDrawable(R.drawable.indicator); |
37 | this.mCurrentDrawable = localResources.getDrawable(R.drawable.indicator_cur); |
40 | public void setMaxPage(int maxNum) |
42 | this.mMaxPage = maxNum; |
48 | arrList = new ArrayList<ImageView>(); |
54 | // ImageView localImageView = new ImageView(this.mContext); |
55 | // localImageView.setPadding(5, 0, 5, 0); |
56 | // if(i==this.mCurrentPage) |
58 | // localImageView.setImageDrawable(this.mCurrentDrawable); |
60 | for (i = 0; i < this.mMaxPage; i++) { |
61 | ImageView localImageView = new ImageView(this.mContext); |
62 | localImageView.setPadding(5, 0, 5, 0); |
63 | addView(localImageView); |
65 | localImageView.setImageDrawable(this.mCurrentDrawable); |
66 | this.arrList.add(localImageView); |
69 | localImageView.setImageDrawable(this.mNormalDrawable); |
70 | this.arrList.add(localImageView); |
78 | setPage(-1+this.mCurrentPage); |
82 | setPage(1+this.mCurrentPage); |
85 | public void setPage(int curPage) |
87 | if(curPage>=this.mMaxPage || curPage<0 || curPage==this.mCurrentPage) |
91 | this.arrList.get(curPage).setImageDrawable(this.mCurrentDrawable); |
92 | this.arrList.get(this.mCurrentPage).setImageDrawable(this.mNormalDrawable); |
93 | this.mCurrentPage = curPage; |
|
|