0

我正在尝试使用 json 文件中的图片创建一个“图库”。我正在使用 RecyclerView 显示带有图片的网格。

当点击一张图片时,它会打开一个新的活动,并将图片信息(url和名称)“发送”到另一个活动,因此它可以下载相同的图片。

无论如何,它不会以最大尺寸或原始尺寸下载图片,而且看起来有点像素化或低分辨率。我还希望图片在不缩放的情况下填满屏幕。这是代码和填满屏幕的图片,但看起来仍然很糟糕。我尝试将 Glide 默认位图格式更改为 ARGB_888,就像在本教程http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en中一样,但没有奏效。

Glide.with(this)
        .load(wallUrl)
        .fitCenter()
        .placeholder(d)
        .into(mPhoto);

布局是

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context="jahirfiquitiva.projects.activities.ViewerActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <jahirfiquitiva.projects.views.TouchImageView
        android:id="@+id/big_wallpaper"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"
        android:scaleType="centerCrop"/>

    <com.melnykov.fab.FloatingActionButton
        android:id="@+id/walls_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="@dimen/fab_margin"
        android:layout_marginEnd="@dimen/fab_margin"
        android:layout_marginRight="@dimen/fab_margin"
        android:src="@drawable/ic_wallpapers_fab"
        fab:fab_colorNormal="@color/white"
        fab:fab_colorPressed="@color/light_grey"
        fab:fab_colorRipple="@color/semitransparent_black" />

</RelativeLayout>

TouchImageView 正是这样:https ://gist.github.com/jahirfiquitiva/daaf5a81f09f21a44175

我还有一个 FAB,按下它会显示一个带有 2 个选项的对话框:应用或保存壁纸。

保存壁纸效果很好。应用也是如此,但是在应用时会使用 MaterialDialogs 库显示一个进度对话框,并且不知何故,当图片似乎即将完成加载时,进度对话框会冻结,所以我想修复它,但不知道什么可以是错的。这是代码:

new MaterialDialog.Builder(context)
                .title(R.string.apply)
                .content(R.string.confirm_apply)
                .positiveText(R.string.yes)
                .negativeText(android.R.string.cancel)
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        final MaterialDialog downloadDialog = new MaterialDialog.Builder(context)
                                .content(R.string.downloading_wallpaper)
                                .progress(true, 0)
                                .cancelable(false)
                                .show();

                        Glide.with(context)
                                .load(url)
                                .asBitmap()
                                .into(new SimpleTarget<Bitmap>() {
                                    @Override
                                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {

                                        if (resource != null) {
                                            downloadDialog.setContent(context.getString(R.string.setting_wall_title));
                                            WallpaperManager wm = WallpaperManager.getInstance(context);
                                            try {
                                                wm.setBitmap(resource);
                                                Toast.makeText(context, R.string.set_as_wall_done, Toast.LENGTH_LONG).show();
                                                Log.v("Wall", "It worked!");
                                            } catch (IOException e2) {
                                                Toast.makeText(context, e2.getLocalizedMessage(), Toast.LENGTH_LONG).show();
                                                Log.v("Wall", "Error " + e2.getMessage());
                                            }
                                            downloadDialog.dismiss();
                                        }
                                    }
                                })
                    }
                }).show();

希望有人可以帮助我解决这两个问题。提前致谢。

4

0 回答 0