Android Studio 和 Firebase:全屏显示 ImageView

我有一个屏幕显示我的电影名称及其在我的 Firebase 中的图片。

我的数据库结构是这样的。name是我的电影名称的字符串。profilePic是包含来自 Firebase 存储的图片链接的字符串。

我想要的是,当我点击列出的任何图片时,我想在另一个更大尺寸的活动中显示它(比如打开某人的 WhatsApp 或 Facebook 个人资料图片)

这些是我的课程,效果很好。我怎样才能做到这一点?

Movies.java

package com.example.XXXX;


import android.content.Intent;

import android.support.annotation.NonNull;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.support.v7.widget.LinearLayoutManager;

import android.support.v7.widget.RecyclerView;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.ImageButton;

import android.widget.ListView;

import android.widget.Toast;


import com.google.firebase.auth.FirebaseAuth;

import com.google.firebase.database.ChildEventListener;

import com.google.firebase.database.DataSnapshot;

import com.google.firebase.database.DatabaseError;

import com.google.firebase.database.DatabaseReference;

import com.google.firebase.database.FirebaseDatabase;

import com.google.firebase.database.ValueEventListener;


import java.util.ArrayList;


public class Movies extends AppCompatActivity {


    DatabaseReference reference;

    RecyclerView recyclerView;

    ArrayList<Profile> list;

    MyAdapter adapter;


    private String message;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_movies);


        recyclerView = (RecyclerView) findViewById(R.id.recyclerview_films);

        recyclerView.setLayoutManager(new LinearLayoutManager(this));




繁星coding
浏览 167回答 3
3回答

胡子哥哥

将视图持有者修改为class MyViewHolder extends RecyclerView.ViewHolder{&nbsp; &nbsp; &nbsp; &nbsp; TextView name;&nbsp; &nbsp; &nbsp; &nbsp; ImageView profilePic;&nbsp; &nbsp; &nbsp; &nbsp; View mView;&nbsp; &nbsp; &nbsp; &nbsp; public MyViewHolder(@NonNull View itemView)&nbsp;&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super(itemView);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mView = itemView;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name = (TextView) itemView.findViewById(R.id.film_name);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; profilePic = (ImageView) itemView.findViewById(R.id.filmProfile);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }在适配器中实现视图持有者的点击侦听器,然后使用图像 url 启动活动。@Overridepublic void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {&nbsp; &nbsp; myViewHolder.name.setText(profiles.get(i).getName());&nbsp; &nbsp; Picasso.get().load(profiles.get(i).getProfilePic()).into(myViewHolder.profilePic);&nbsp;&nbsp;&nbsp; &nbsp; mViewHolder.mView.setOnClickListener(new View.OnClickListener(){&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public void onClick(View v) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; startImageActivity(profiles.get(i).getProfilePic());&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });}3.创建活动并从所需尺寸的图像视图开始。&nbsp; &nbsp; void startImageActivity(String imgUrl)&nbsp; &nbsp; {&nbsp; &nbsp; Intent intent = new Intent(context,ViewImage.class);&nbsp; &nbsp; intent.putExtra("profilePic",imgUrl);&nbsp; &nbsp; context.startActivity(intent);&nbsp; &nbsp; }或者在外部应用程序中打开图像尝试&nbsp; &nbsp; void startImageActivity(String imgUrl)&nbsp; &nbsp; {&nbsp; &nbsp;Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(imgUrl));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;context.startActivity(intent);&nbsp; &nbsp; }

MM们

调整位图大小:Bitmap&nbsp;resizedBitmap&nbsp;=&nbsp;Bitmap.createScaledBitmap( &nbsp;&nbsp;&nbsp;&nbsp;originalBitmap,&nbsp;newWidth,&nbsp;newHeight,&nbsp;false);

MMTTMM

您可以使用此库进行放大和缩小功能,你需要在你的项目中添加这个 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);                        }                    });        }    }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java