gallery点击无响应
package suhq.android.projects.make; import android.R.integer; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.view.ViewGroup.LayoutParams; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.BaseAdapter; import android.widget.ViewSwitcher.ViewFactory; import android.widget.ArrayAdapter; import android.widget.Gallery; import android.widget.ImageSwitcher; import android.widget.ImageView; public class Iphoto extends Activity implements ViewFactory{ ImageSwitcher imgSwitcher; Gallery gallery; private int[] imgSource; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.i_photo); setupViews(); } private void setupViews(){ imgSource=new int[]{R.drawable.lump_background_1,R.drawable.lump_background_2,R.drawable.lump_background_3, R.drawable.lump_background_4,R.drawable.lump_background_5,R.drawable.lump_background_6, R.drawable.lump_background_7,R.drawable.lump_background_8,R.drawable.lump_background_9, R.drawable.lump_background_10,R.drawable.lump_background_11,R.drawable.lump_background_12}; imgSwitcher=(ImageSwitcher)findViewById(R.id.imgSwitcher); gallery=(Gallery)findViewById(R.id.gallery); imgSwitcher.setFactory(this); imgSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.out_to_left)); imgSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.in_from_right)); gallery.setAdapter(new ImageAdapter(this, imgSource)); gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) { Drawable drawable=Iphoto.this.getResources().getDrawable(imgSource[position]); Bitmap bitmap = ImageUtil.drawableToBitmap(drawable); //缩放图片 //Bitmap zoomBitmap = ImageUtil.zoomBitmap(bitmap, 100, 100); //获取圆角图片 // Bitmap roundBitmap = ImageUtil.getRoundedCornerBitmap(zoomBitmap, 10.0f); //获取倒影图片 Bitmap reflectBitmap = ImageUtil.createReflectionImageWithOrigin(bitmap); drawable=ImageUtil.bitmapToDrawable(Iphoto.this,reflectBitmap); imgSwitcher.setImageDrawable(drawable);Log.i("suhq24","dfgfggh"); //} } public void onNothingSelected(AdapterView<?> adapterView) { } }); //这里可以让Bitmap再转化为Drawable // Drawable roundDrawable = new BitmapDrawable(roundBitmap); // Drawable reflectDrawable = new BitmapDrawable(reflectBitmap); // mImageView01.setBackgroundDrawable(roundDrawable); // mImageView02.setBackgroundDrawable(reflectDrawable); } public View makeView() { ImageView imgView=new ImageView(this); //imgView.setBackgroundColor(Color.CYAN); imgView.setScaleType(ImageView.ScaleType.CENTER_CROP); imgView.setLayoutParams(new ImageSwitcher.LayoutParams(180, 260)); return imgView; } protected class ImageAdapter extends BaseAdapter{ private Context context; private int[] imgIds; public ImageAdapter(Context context,int[] imgIds) { this.imgIds=imgIds; this.context=context; } public int getCount(){ return imgIds.length; } public Object getItem(int item){ return item; } public long getItemId(int id){ return id; } public View getView(final int position, View convertView,ViewGroup parent){ ImageView imgView; if (convertView==null) { imgView=new ImageView(context); imgView.setAdjustViewBounds(false); imgView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));//设置ImageView边界布局 imgView.setClickable(true); imgView.setPadding(0, 2, 8, 2); imgView.setImageResource(imgIds[position]); }else { imgView=(ImageView)convertView; } return imgView; } } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我要的是onItemSelectedLisener 。该事件在我刚运行程序时执行了一次,之后要选择其他图片时无响应
点击事件是setOnClickListener