【问题标题】:fullScreen ImageView close全屏 ImageView 关闭
【发布时间】:2017-07-26 23:40:14
【问题描述】:

这是我的代码:

final ImageView imageView1 = (ImageView) findViewById(R.id.imageView8);
    imageView1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            imageView1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT));
        }
    });

当我点击我的 ImageView 时,通过这段代码,我可以在全屏中看到它。 现在我有一个问题: 当我在全屏中看到 imageView 时,当我按下 Back 时,此 imageView 将关闭并返回到以前的情况,并且我的应用程序不会返回到以前的活动

【问题讨论】:

  • 你需要问一个实际的问题。

标签: android imageview


【解决方案1】:

而不是全屏打开图像,您可以使用自定义对话框打开该图像,称为全图像对话框,其工作方式与 AlertDialog 完全相同,因为您只需要设计一个自定义布局,包括宽度和高度您正在打开的图像。它易于维护,因为单击屏幕上的任意位置对话框会自动关闭,您的活动将恢复。 如果你愿意,我可以给你更多的想法?

【讨论】:

  • 我是安卓初学者。请为我发送代码。谢谢
  • 好的,我在下一个答案中编写代码,提示您如何实现它
  • 如果上面的代码对你有用,那么请批准答案
【解决方案2】:

第 1 步:创建一个类 FullImageDialog 具有此方法:

public static void showImage(Context context, String strImagePath) {
        AlertDialog.Builder imageDialog = new AlertDialog.Builder(context);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.custom_fullimage_dialog, null);
        ImageView image = (ImageView) layout.findViewById(R.id.fullImage);

        Glide.with(context)
                .load(strImagePath)
                .placeholder(R.drawable.default_user_image)
                .dontAnimate()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(image);
        //image.setImageDrawable(tempImageView.getDrawable());

        imageDialog.setView(layout);

        final AlertDialog alert= imageDialog.create();
        alert.getWindow().getAttributes().windowAnimations=R.style.FadeInTheme;
        alert.show();
    }

第二步:创建full_image_dialog的xml为:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/layout_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/fullImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:background="@drawable/default_user_image"
        android:scaleType="fitXY" />

</LinearLayout>

第三步:调用需要打开此对话框的方法:

final ImageView imageView1 = (ImageView) findViewById(R.id.imageView8);
    imageView1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
      //call FullImageDialog class by giving parameter of imageUrl
      FullImageDialog.showImage(imageUrl);

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多