[英]Show full size image of the clicked grid image
Main Activity.java 主Activity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_grid);
// populate data
products = new ArrayList();
products.add(new Product("http://image1.jpg"));
products.add(new Product("http://image2.jpg"));
products.add(new Product("http://image3"));
products.add(new Product("http://image4"));
//
gvProducts = (GridView) findViewById( R.id.grid_products);
adapterProducts = new ProductListAdapterWithCache(this, products);
gvProducts.setAdapter(adapterProducts);
gvProducts.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
String path = (MainActivity.this, position);
Intent intent = new Intent(MainActivity.this, FullImageActivity.class);
intent.putExtra("IMAGEPATH",path);
startActivity(intent);
}
});
}
I am developing simple image processing app in android studio. 我正在android studio中开发简单的图像处理应用程序。 I am downloading images from the
url
to show in grid as above.. I want to show the full image in page when the grid is clicked.. trying to pass the position through intent but its showing error on this line.. 我正在从
url
下载图像,如上所示在网格中显示..我想在点击网格时显示页面中的完整图像..尝试通过意图传递位置,但在此行显示错误..
String path = (MainActivity.this, position);
FullImageActivity.java FullImageActivity.java
public class FullImageActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_fullscreen_image);
// selected item
int imageInt = getIntent().getIntExtra("IMAGEPATH", R.drawable.spinner);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageResource(imageInt);
}
}
I am a beginner so guide me if I have done anything wrong in the basics. 我是初学者,如果我在基础知识上做了任何错误,请指导我。
Thanks, 谢谢,
Try below code: 试试以下代码:
gvProducts.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Intent intent = new Intent(MainActivity.this, FullImageActivity.class);
intent.putExtra("IMAGEPATH",products.get(position).imagePath);
startActivity(intent);
}
});
In Activity: 在活动中:
String path = getIntent().getStringExtra("IMAGEPATH");
I would suggest you to use PhotoView and Universal Image Loader , refer to the example code in the PhotoView Project, and i also provide some code, hope this will help. 我建议你使用PhotoView和Universal Image Loader ,参考PhotoView项目中的示例代码,我也提供一些代码,希望这会有所帮助。
Java Code snippet: Java代码段:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.diary_imageview);
imageUrl = getIntent().getStringExtra(IMAGE_URL);
mProgress.setVisibility(View.VISIBLE);
mAttacher = new PhotoViewAttacher(mPhotoView);
mAttacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
@Override
public void onPhotoTap(View view, float v, float v2) {
finish();
}
});
ImageLoader.getInstance().displayImage(imageUrl, mPhotoView, Util.getDisplayImageOptions(), new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
mProgress.setVisibility(View.GONE);
mAttacher.update();
}
});
}
XML layout: XML布局:
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<uk.co.senab.photoview.PhotoView
android:id="@+id/photoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
<ProgressBar
android:id="@+id/progress"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
</merge>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.