gpt4 book ai didi

java - 转到全图像屏幕

转载 作者:行者123 更新时间:2023-12-02 11:04:04 25 4
gpt4 key购买 nike

我制作了一个 Android 应用程序,将 Firebase 中的图像显示到回收器 View 中,当用户单击图像时,它必须转到全屏页面并尝试了几次,但它只显示空白 Activity

最佳答案

您可以使用PhotoView库(com.github.chrisbanes.photoview)来显示全屏图片,如下所示:这里使用 Piccaso 来显示图像,但您可以使用其他图像库,例如 Fresco、Glide 。

ActivityLargeImageView

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.github.chrisbanes.photoview.PhotoView;
import com.github.chrisbanes.photoview.PhotoViewAttacher;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import java.io.File;
import butterknife.BindView;
import butterknife.ButterKnife;

public class ActivityLargeImageView extends FragmentActivity {

@BindView(R.id.photoview_image)
PhotoView photoviewImage;
@BindView(R.id.progressbar)
ProgressBar progressBar;


File mFile;
PhotoViewAttacher mAttacher;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_large_image_view);
ButterKnife.bind(this);

progressBar.setVisibility(View.VISIBLE);
String img_url = getIntent().getExtras().getString("image_url");

try {
mFile = new File(img_url);
} catch (Exception ex) {

}


if (mFile.exists()) {
Picasso.with(getApplicationContext()).load(mFile).into(photoviewImage, imageLoadedCallback);

} else {
Picasso.with(getApplicationContext()).load(img_url).into(photoviewImage, imageLoadedCallback);
}
}

Callback imageLoadedCallback = new Callback() {

@Override
public void onSuccess() {
if (mAttacher != null) {
mAttacher.update();
} else {
mAttacher = new PhotoViewAttacher(photoviewImage);
}

progressBar.setVisibility(View.GONE);
}

@Override
public void onError() {

Toast.makeText(getApplicationContext(), getResources().getString(R.string.error_message_connection_to_server), Toast.LENGTH_LONG).show();
}
};

}

XML 文件

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:background="#000000"
android:orientation="vertical" >


<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photoview_image"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />


</FrameLayout>

关于java - 转到全图像屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51113139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com