使用ImageSwitcher点击按钮浏览图片
2014-06-29 10:52
309 查看
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <LinearLayout android:layout_width="fill_parent" android:layout_height="250dp" android:gravity="center"> <ImageSwitcher android:id="@+id/IS01" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ImageSwitcher> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/pre" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="上一张" /> <Button android:id="@+id/next" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="下一张" /> </LinearLayout> </LinearLayout>
package com.example.imageswitcher; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.ViewSwitcher.ViewFactory; public class MainActivity extends Activity implements ViewFactory, OnClickListener { private final static Integer[] INTEGERS = { R.drawable.a, R.drawable.d, R.drawable.c, R.drawable.d, R.drawable.e, R.drawable.f, R.drawable.g, R.drawable.h, }; ImageSwitcher imageSwitcher; Button button,button2; private static int index=0; private final static int DOWN_ID = 0x123456; private final static int UP_ID = 0x123456; private final static int SWICHER_ID = 0x123456; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageSwitcher = (ImageSwitcher)findViewById(R.id.IS01); button = (Button)findViewById(R.id.pre); button2 = (Button)findViewById(R.id.next); imageSwitcher.setFactory(this); imageSwitcher.setImageResource(INTEGERS[index]); button.setOnClickListener(this); button2.setOnClickListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public View makeView() { return new ImageView(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.pre: index--; if(index<0){ index = INTEGERS.length-1; } imageSwitcher.setImageResource(INTEGERS[index]); break; case R.id.next: index++; if(index>=INTEGERS.length){ index = 0; } imageSwitcher.setImageResource(INTEGERS[index]); break; } } }
相关文章推荐
- 使用ImageSwitcher实现点击按钮浏览图片功能
- 使用ColorBox弹出图片组浏览层,点击换图
- 使用ImageSwitcher和Gallery实现图片的浏览
- 使用ImageSwitcher和Gallery实现图片的浏览
- android 使用xml selector设置按钮点击效果图片
- Fileupload控件点击“浏览”按钮,选择图片后需要立即显示所选择的图片
- 使用:target实现点击按钮切换图片的功能(纯CSS)
- Android笔记- 使用XML selector 设置按钮点击效果图片
- 简单图片浏览工具—ImageSwitcher和Gallery组件结合使用
- js 实现点击浏览图片按钮时同时显示图片
- 使用 StoryBoard 实现左右按钮切换图片的浏览效果
- OutLook样式类使用过程,弹出模式对话框时候,鼠标不能点击对话框按钮,的问题。
- 在silverlight中使用OpenFileDialog浏览本地图片
- DHTML工具栏,Web点击更精彩(4)--使用按钮
- 英语音标的录入。点击按钮,点击图片,点击图标等,在RTF文本框中显示字体中的字符。
- 在silverlight中使用OpenFileDialog浏览本地图片
- DataGrid的EditCommandColumn如何使用图片作为按钮
- 使用sendmessage函数模拟点击其他程序按钮事件