直奔主题~!

结构如图:

第五篇 ImageSwitcher篇

main.xml代码:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent" android:gravity="center"><ImageSwitcher android:id="@+id/is"android:layout_width="fill_parent" android:layout_height="200dip"></ImageSwitcher><LinearLayout android:layout_width="fill_parent"android:id="@+id/linearLayout1" android:layout_height="wrap_content"android:gravity="center"><Button android:text="上一页" android:id="@+id/up_btn"android:layout_width="wrap_content" android:layout_height="wrap_content"></Button><Button android:text="下一页" android:id="@+id/next_btn"android:layout_width="wrap_content" android:layout_height="wrap_content"></Button></LinearLayout></LinearLayout>

Control_ImageSwitcherActivity.java代码:

public class Control_ImageSwitcherActivity extends Activity {ImageSwitcher is;Button next_btn;Button up_btn;int[] imggroup;int index=0;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        findAll();        bind();    }        public void findAll()    {    is=(ImageSwitcher) this.findViewById(R.id.is);    next_btn=(Button) this.findViewById(R.id.next_btn);    up_btn=(Button) this.findViewById(R.id.up_btn);    }        public void bind()    {    imggroup=new int[]{R.raw.jwc1,R.raw.jwc2,R.raw.jwc3,R.raw.jwc4,R.raw.jwc5};    next_btn.setOnClickListener(mylistener);    up_btn.setOnClickListener(mylistener);    is.setFactory(new ViewFactory() {       public View makeView() {// TODO Auto-generated method stub//return null;ImageView iv=new ImageView(Control_ImageSwitcherActivity.this);iv.setLayoutParams(new  ImageSwitcher.LayoutParams(100, 100));return iv;}});    is.setBackgroundResource(imggroup[index]);    }                private View.OnClickListener mylistener =new OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubswitch(v.getId()){case R.id.up_btn:if(index>=1){   index--;   is.setBackgroundResource(imggroup[index]);}else{  Toast.makeText(Control_ImageSwitcherActivity.this, "已经到了第一页", Toast.LENGTH_LONG).show();}break;case R.id.next_btn:if(index<(imggroup.length-1)){   index++;   is.setBackgroundResource(imggroup[index]);}else{  Toast.makeText(Control_ImageSwitcherActivity.this, "已经到了最后一页", Toast.LENGTH_LONG).show();}break;default:break;}}};}

更多相关文章

  1. Android的Gson的使用方法,实现Json结构间相互转换
  2. android重启代码
  3. Android 源码目录结构
  4. android 发布正式版时用Gradle移除日志打印代码(添加混淆配置)
  5. android Camera 结构
  6. [置顶] android studio 如何进行格式化代码 快捷键必备

随机推荐

  1. MySQL修改root密码的多种方法(推荐)
  2. 完美解决mysql客户端授权后连接失败的问
  3. mysqldump备份数据库时排除某些库的实例
  4. mysql完整备份时过滤掉某些库的方法
  5. Mysql数据库之Binlog日志使用总结(必看篇
  6. MySQL修改默认存储引擎的实现方法
  7. Mysql更换MyISAM存储引擎为Innodb的操作
  8. MACOS中忘记MySQL root密码的解决方案
  9. Mysql 5.7.17忘记密码怎么办
  10. mysql 行转列和列转行实例详解