我想通过单击网格视图项目来显示全屏图像。我已经完成了网格视图,但不知道如何做到这一点。请给予我一些想法来做到这一点??谢谢....!
mGridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Image"+(position+1), Toast.LENGTH_SHORT).show();
Intent intent =new Intent(getApplicationContext(),MyImageViewActivity.class);
intent.putExtra("filename", i);
startActivity(intent);
}
});
MyGridView.java
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyStore.LoadStoreParameter;
import com.myworkspace.R.menu;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.ContactsContract.CommonDataKinds.Im;
import android.provider.MediaStore.Audio.Media;
import android.provider.SyncStateContract.Columns;
import android.sax.StartElementListener;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class MyGridView extends Activity {
GridView mGridView;
int counter,i;
MyImageAdapter adapter = null;
ImageView imgVw;
Bitmap bitmap;
private Cursor cursor;
int columnIndex;
Integer[] mThumbsIds = {
R.drawable.image1,R.drawable.image2,
R.drawable.image3,R.drawable.image4,
R.drawable.image5,R.drawable.icon,
R.drawable.icon,R.drawable.icon,
R.drawable.icon
};
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mygridacti);
ImageView imageview = (ImageView)findViewById(R.id.GalleryView);
mGridView = (GridView)findViewById(R.id.grdvw);
adapter = new MyImageAdapter(this);
adapter.notifyDataSetChanged();
mGridView.setAdapter(adapter);
mGridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Image"+(position+1), Toast.LENGTH_SHORT).show();
Intent myIntent = new Intent(MyGridView.this, MyImageViewActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("image", mThumbsIds[position]);
myIntent.putExtras(bundle);
startActivityForResult(myIntent, 0);
}
});
}
}
class MyImageAdapter extends BaseAdapter{
private Context mContext;
ImageView imageview;
int counter;
public MyImageAdapter(Context c){
mContext = c;
}
public MyImageAdapter(OnClickListener onClickListener) {
// TODO Auto-generated constructor stub
}
@Override
public int getCount() {
return mThumbsIds.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(final int position, final View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView == null){
imageview = new ImageView(mContext);
imageview.setLayoutParams(new GridView.LayoutParams(85,85));
imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageview.setPadding(8, 8, 8, 8);
counter++;
}
else{
imageview = (ImageView) convertView;
}
imageview.setImageResource(mThumbsIds[position]);
return imageview;
}
private Integer[] mThumbsIds = {
R.drawable.image1,R.drawable.image2,
R.drawable.image3,R.drawable.image4,
R.drawable.image5,R.drawable.icon,
R.drawable.icon,R.drawable.icon,
R.drawable.icon};
}
3条答案
按热度按时间33qvvth11#
您知道如何在gridView中显示图像。在此之后执行以下操作
ViewImage.class
omqzjyyz2#
您应该在您的
setOnItemClickListener
中执行类似的操作,我正在使用您的代码并对其进行改进如果您现在在
ViewImage.class
中仅发送单个图像ID,则无需传递Bundle
。您可以使用以下命令从Intent获取图像我将使用Glide向您展示如何在ImageView中显示此图像
希望这会有帮助!
62o28rlo3#
在itemClick上,只需传递
position
在其他活动中,