3 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊
將視圖持有者修改為
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);
}
}
在適配器中實(shí)現(xiàn)視圖持有者的點(diǎn)擊偵聽器,然后使用圖像 url 啟動(dòng)活動(dòng)。
@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.創(chuàng)建活動(dòng)并從所需尺寸的圖像視圖開始。
void startImageActivity(String imgUrl)
{
Intent intent = new Intent(context,ViewImage.class);
intent.putExtra("profilePic",imgUrl);
context.startActivity(intent);
}
或者在外部應(yīng)用程序中打開圖像嘗試
void startImageActivity(String imgUrl)
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(imgUrl));
context.startActivity(intent);
}

TA貢獻(xiàn)1886條經(jīng)驗(yàn) 獲得超2個(gè)贊
調(diào)整位圖大?。?/strong>
Bitmap resizedBitmap = Bitmap.createScaledBitmap( originalBitmap, newWidth, newHeight, false);

TA貢獻(xiàn)1869條經(jīng)驗(yàn) 獲得超4個(gè)贊
您可以使用此庫進(jìn)行放大和縮小功能,
你需要在你的項(xiàng)目中添加這個(gè) gradle
實(shí)施 '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 進(jìn)行圖像加載,如下所示
?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);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? });
? ? ? ? }
? ? }
}
添加回答
舉報(bào)