Android开发 - 实现点击图片切换效果
fmms
13年前
<p>在资源中添加5张图片,重命名为a-e 。</p> <p>实现java代码如下:</p> <pre class="brush:java; toolbar: true; auto-links: false;">package cn.csdn.android.test; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; import android.widget.LinearLayout; public class Android_test2Activity extends Activity{ int [] image = new int []{ R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d, R.drawable.e }; int currentImg = 0; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.id.root); LinearLayout main = (LinearLayout) findViewById(R.id.root); final ImageView images = new ImageView(this); main.addView(images); images.setImageResource(image[0]); images.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(currentImg>=4){ currentImg=-1; } images.setImageResource(image[++currentImg]); } }); } }</pre>来自: <a href="/misc/goto?guid=4959500610175101589" target="_blank">http://blog.csdn.net/yangbo_hbzjk/article/details/7193572</a> <p></p>