2.1.4 实现简单图片浏览

来源:互联网 发布:linux下链接数据库 编辑:程序博客网 时间:2024/05/01 14:00
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:id="@+id/root"    android:layout_height="match_parent">    <ImageView        android:layout_width="match_parent"        android:layout_height="200dp"        android:id="@+id/img"        android:scaleType="fitXY"/></LinearLayout>
public class One extends Activity {    private int [] images = new int[]{            R.mipmap.one1,            R.mipmap.one2    };    private int currentImage = 0;    private ImageView imageView = null;    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.one);        init();    }    private void init(){        imageView = (ImageView) findViewById(R.id.img);        imageView.setImageResource(images[currentImage]);        imageView.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                currentImage++;                if (currentImage == images.length)                {                    currentImage = 0;                }                imageView.setImageResource(images[currentImage]);            }        });    }}

这里写图片描述

原创粉丝点击