单击“回收者"视图中的项目时,查看全屏图像 [英] view full screen image when item from recycler view clicks
问题描述
我是android的新手,我有一个RecyclerView可以显示json的图像列表.我想在RecyclerView的项目单击时做到全屏显示图像,而且应该可以放大和缩小. ).缩放功能是使用Photoview Library完成的,但是无法全屏查看项目.下面附有适配器类代码.请任何人帮助我做到这一点.
I am new to android.I have a RecyclerView which shows list of images from a json.I want to do showing image full screen when item from RecyclerView clicks.Also it should be able to zoom in and out.(Like gallery).Zooming functionalty is done using Photoview Library.But viewing full screen a item is not done.Adapter class code is attached below.Please anyone help me to do this.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
final MyHolder myHolder = (MyHolder) holder;
DataFish current = data.get(position);
// load image into imageview using glide
Glide.with(context).load(current.flagimage)
.placeholder(R.drawable.ic_launcher_background)
.error(R.drawable.ic_launcher_background)
.into(myHolder.imageView);
myHolder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
我想在此onclick中添加用于全屏查看的代码.
I want to add the code for view full screen in this onclick.
推荐答案
按照以下步骤
像这样创建一个新的Activity并获取网址
create a new Activity like this and retrive url
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/myImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
</LinearLayout>
Activity.java
Activity.java
public class MainActivity extends AppCompatActivity {
ImageView myImage;
String url = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
url = getIntent().getStringExtra("image_url");
myImage = findViewById(R.id.myImage);
Glide.with(this).load(url)
.placeholder(R.drawable.ic_launcher_background)
.error(R.drawable.ic_launcher_background)
.into(myImage);
}
}
使用click om recyclerview项时,使用意图将URL传递给该活动
When use click om recyclerview item than pass the url to that activity using intent
myHolder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new Intent(context,MainActivity.this);
intent.putExtra("image_url",current.flagimage);
context.startActivity(intent);
}
});
您可以使用
PhotoView
来缩放ImageView
>
you can use
PhotoView
for zoomingImageView
PhotoView
旨在帮助生成易于使用的缩放Android ImageView
实施.
这篇关于单击“回收者"视图中的项目时,查看全屏图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!