阳光网驿-企业信息化交流平台【DTC零售连锁全渠道解决方案】

 找回密码
 注册

QQ登录

只需一步,快速开始

扫描二维码登录本站

手机号码,快捷登录

老司机
查看: 1266|回复: 0

[转帖] 一组图片,自定义页码控件

[复制链接]
  • TA的每日心情
    开心
    2012-3-7 10:15
  • 签到天数: 11 天

    [LV.3]偶尔看看II

    发表于 2012-1-3 11:21:58 | 显示全部楼层 |阅读模式
    01import java.util.ArrayList;
    02

    03import com.cric.R;

    04

    05import android.content.Context;

    06import android.content.res.Resources;

    07import android.graphics.drawable.Drawable;

    08import android.util.AttributeSet;

    09import android.widget.ImageView;

    10import android.widget.LinearLayout;

    11

    12public class PageIndicator extends LinearLayout {

    13

    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) {

    21        super(context);

    22        this.mContext = context;

    23        // TODO Auto-generated constructor stub

    24    }

    25     

    26    public PageIndicator(Context paramContext, AttributeSet paramAttributeSet)

    27    {

    28        super(paramContext, paramAttributeSet);

    29        this.mContext = paramContext;

    30        loadDefaultDrawable();

    31    }

    32     

    33    private void loadDefaultDrawable()

    34    {

    35        Resources localResources = this.mContext.getResources();

    36        this.mNormalDrawable = localResources.getDrawable(R.drawable.indicator);

    37        this.mCurrentDrawable = localResources.getDrawable(R.drawable.indicator_cur);

    38    }

    39     

    40    public void setMaxPage(int maxNum)

    41    {

    42        this.mMaxPage = maxNum;

    43        init();

    44    }

    45     

    46    private void init(){

    47        removeAllViews();

    48        arrList = new ArrayList<ImageView>();

    49        int i = 0 ;

    50        if(i>=this.mMaxPage)

    51        {

    52            return;

    53        }

    54//      ImageView localImageView = new ImageView(this.mContext);

    55//      localImageView.setPadding(5, 0, 5, 0);

    56//      if(i==this.mCurrentPage)

    57//      {

    58//          localImageView.setImageDrawable(this.mCurrentDrawable);

    59//      }

    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);

    64            if(i==0){

    65                localImageView.setImageDrawable(this.mCurrentDrawable);

    66                this.arrList.add(localImageView);

    67            }else

    68            {

    69                localImageView.setImageDrawable(this.mNormalDrawable);

    70                this.arrList.add(localImageView);

    71            }

    72            

    73        }

    74         

    75    }

    76     

    77    public void pre(){

    78        setPage(-1+this.mCurrentPage);

    79    }

    80     

    81    public void next(){

    82        setPage(1+this.mCurrentPage);

    83    }

    84     

    85    public void setPage(int curPage)

    86    {

    87        if(curPage>=this.mMaxPage || curPage<0 || curPage==this.mCurrentPage)

    88        {

    89            return;

    90        }

    91        this.arrList.get(curPage).setImageDrawable(this.mCurrentDrawable);

    92        this.arrList.get(this.mCurrentPage).setImageDrawable(this.mNormalDrawable);

    93        this.mCurrentPage = curPage;

    94    }

    95     

    96     

    97

    98}

    楼主热帖
    启用邀请码注册,提高发帖质量,建设交流社区
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    快速回复 返回顶部 返回列表