ImageSwitcher的初用
2015-10-23 11:39
295 查看
一,切换图片类,ImageSwitcher, 上一张,下一张查看图片的类。
//viewFactory 主要用来将显示的图片和父窗口区分开来
public class ImageSwitcherActivity extends Activity implements ViewFactory {
private int[] drawables = { R.drawable.aa, R.drawable.bb, R.drawable.cc, R.drawable.dd, R.drawable.ee,
R.drawable.ff, R.drawable.gg };
private ImageSwitcher mSwitcher;//切换图片类
private static int index=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_imageswitcher_text);
mSwitcher=(ImageSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
mSwitcher.setImageResource(drawables[index]);
}
public void myclick(View v){
switch (v.getId()) {
case R.id.up:
index++;
if(index>=drawables.length-1)
index=0;
break;
case R.id.down:
index--;
if(index<0)
index=drawables.length-1;
break;
}
mSwitcher.setImageResource(drawables[index]);
}
//显示图片的类。
@Override
public View makeView() {
return new ImageView(this);
}
}
二,对就的xml类。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageSwitcher
android:id="@+id/switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ImageSwitcher>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="@+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dip"
android:onClick="myclick"
android:text="上一张" />
<Button
android:id="@+id/down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="myclick"
android:text="下一张" />
</LinearLayout>
</LinearLayout>
三,对应的效果图:
//viewFactory 主要用来将显示的图片和父窗口区分开来
public class ImageSwitcherActivity extends Activity implements ViewFactory {
private int[] drawables = { R.drawable.aa, R.drawable.bb, R.drawable.cc, R.drawable.dd, R.drawable.ee,
R.drawable.ff, R.drawable.gg };
private ImageSwitcher mSwitcher;//切换图片类
private static int index=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_imageswitcher_text);
mSwitcher=(ImageSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
mSwitcher.setImageResource(drawables[index]);
}
public void myclick(View v){
switch (v.getId()) {
case R.id.up:
index++;
if(index>=drawables.length-1)
index=0;
break;
case R.id.down:
index--;
if(index<0)
index=drawables.length-1;
break;
}
mSwitcher.setImageResource(drawables[index]);
}
//显示图片的类。
@Override
public View makeView() {
return new ImageView(this);
}
}
二,对就的xml类。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageSwitcher
android:id="@+id/switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ImageSwitcher>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="@+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dip"
android:onClick="myclick"
android:text="上一张" />
<Button
android:id="@+id/down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="myclick"
android:text="下一张" />
</LinearLayout>
</LinearLayout>
三,对应的效果图:
相关文章推荐
- Android入门之Gallery+ImageSwitcher用法实例解析
- 【Android】图片切换组件ImageSwitcher的运用
- Android UI控件之ImageSwitcher(图片切换)
- Android幻灯片式图片浏览器
- Gallery图片轮播
- Android利用Gallery和ImageSwitcher实现在线相册图片预览功能(异步加载图片)
- android 图片切换 ImageSwitcher
- GridView和ImageSwitcher的功能和用法
- Hack5-用TextSwitcher和ImageSwitcher打造漂亮的动画效果
- ImageSwitcher 和 Gallery 的使用
- Android:TextSwitcher、imageSwitcher
- Android零基础入门第55节:ImageSwitcher和TextSwitcher使用
- 画廊布局(ImageSwitcher与Gallery)
- imageswitcher+gallay实现相册功能
- Android中画廊视图Gallery和ImageSwitcher组件的使用(十三)
- VIewAnimator及其子类
- Gallery和ImageSwitcher
- AnimationDrawable监听播放结束及ImageSwitcher动画图片切换,带动画
- Android-ImageSwitcher-详解
- 【Android基础知识】使用Gallery和ImageSwitcher实现图片轮播效果