3 回答
TA贡献1934条经验 获得超2个赞
将视图持有者修改为
class MyViewHolder extends RecyclerView.ViewHolder
{
TextView name;
ImageView profilePic;
View mView;
public MyViewHolder(@NonNull View itemView)
{
super(itemView);
mView = itemView;
name = (TextView) itemView.findViewById(R.id.film_name);
profilePic = (ImageView) itemView.findViewById(R.id.filmProfile);
}
}
在适配器中实现视图持有者的点击侦听器,然后使用图像 url 启动活动。
@Override
public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
myViewHolder.name.setText(profiles.get(i).getName());
Picasso.get().load(profiles.get(i).getProfilePic()).into(myViewHolder.profilePic);
mViewHolder.mView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
startImageActivity(profiles.get(i).getProfilePic());
}
});
}
3.创建活动并从所需尺寸的图像视图开始。
void startImageActivity(String imgUrl)
{
Intent intent = new Intent(context,ViewImage.class);
intent.putExtra("profilePic",imgUrl);
context.startActivity(intent);
}
或者在外部应用程序中打开图像尝试
void startImageActivity(String imgUrl)
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(imgUrl));
context.startActivity(intent);
}
TA贡献2037条经验 获得超6个赞
您可以使用此库进行放大和缩小功能,
你需要在你的项目中添加这个 gradle
实施 'com.otaliastudios:zoomlayout:1.6.1'
检查下面的示例布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_grey"
android:orientation="vertical"
android:weightSum="13">
<ImageView
android:id="@+id/iv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="@dimen/margin_small"
android:padding="@dimen/margin_small"
android:src="@drawable/ic_skip" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="6" />
<com.otaliastudios.zoom.ZoomImageView
android:id="@+id/zoom_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:scrollbars="vertical|horizontal"
app:alignment="center"
app:animationDuration="280"
app:flingEnabled="true"
app:horizontalPanEnabled="true"
app:maxZoom="2.5"
app:maxZoomType="zoom"
app:minZoom="0.7"
app:minZoomType="zoom"
app:overPinchable="true"
app:overScrollHorizontal="true"
app:overScrollVertical="true"
app:transformation="centerInside"
app:transformationGravity="auto"
app:verticalPanEnabled="true"
app:zoomEnabled="true" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="5" />
</LinearLayout>
在JAVA类中,您需要像下面这样加载图像,我正在使用 Glide 进行图像加载,如下所示
GlideApp.with(this)
.asBitmap()
.load(YOUR_IMAGE_URL)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
YOUR_IMAGEVIEW.setImageBitmap(resource);
}
});
检查ZoomActivity.java下面的演示目的
public class ZoomActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_zoom);
// ActivityZoomBinding mBinding = DataBindingUtil.setContentView(this, R.layout.activity_zoom);
ImageView zoomImage = findViewById(R.id.zoom_image);
///GETTING INTENT DATA
Intent intent = getIntent();
if (intent.hasExtra("ZOOM_IMAGE")) {
String imageUrl = intent.getStringExtra("ZOOM_IMAGE");
GlideApp.with(this)
.asBitmap()
.load(imageUrl)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
zoomImage.setImageBitmap(resource);
}
});
}
}
}
TA贡献1777条经验 获得超10个赞
调整位图大小:
Bitmap resizedBitmap = Bitmap.createScaledBitmap( originalBitmap, newWidth, newHeight, false);
添加回答
举报