简体   繁体   English

图片始终位于对话框顶部

[英]image always placed in top of dialog

I am displaying image in the dialog box which contains the zoom view as well. 我也在包含缩放视图的对话框中显示图像。 Here image is placed and zoom is working fine without any issue but problem is image is always placed in the top of the dialog and if i scroll down it comes to middle then zoom happens. 在这里放置了图像,并且缩放正常,没有任何问题,但是问题是图像始终放在对话框的顶部,如果我向下滚动,它会居中,然后发生缩放。 I dont want like this instead image should display in the middle and i need to do the zoom. 我不希望这样,图像应该显示在中间,我需要进行缩放。

I am using dynamic imageview and for zoom using chrisbanes photoview library. 我正在使用动态imageview,并使用chrisbanes photoview库进行缩放。 If i remove the library the image is placed in the center. 如果我删除库,则图像将放置在中央。

 @Override
            public void onClick(View v) {

                Dialog builder = new Dialog(listdisplay, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
                builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
                builder.getWindow().setBackgroundDrawable(
                        new ColorDrawable(Color.BLACK));
                builder.setCanceledOnTouchOutside(false);
                builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        //nothing;
                    }
                });

 ImageView imageView = new ImageView(listdisplay);
                      Glide.with(finalConvertView.getContext()).load(Limage).fitCenter()
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(imageView);

                DisplayMetrics metrics = new DisplayMetrics();
                listdisplay.getWindowManager().getDefaultDisplay().getMetrics(metrics);


                LinearLayout.LayoutParams lp =  new LinearLayout.LayoutParams(metrics.widthPixels,
                        metrics.heightPixels);

                imageView.setLayoutParams(lp);

                //imageView.setScaleType(ImageView.ScaleType.CENTER);
                 p = new PhotoViewAttacher(imageView);


                builder.addContentView(imageView, lp);
                builder.show();
            }
        });

i tried with scaletype for imageview as center but image is placed in top of the dialog. 我尝试使用scaletype以imageview为中心,但是图像放置在对话框的顶部。

在此处输入图片说明

在此处输入图片说明

Use Custom dialog for you own dialog design 使用自定义对话框进行自己的对话框设计

            final Dialog dialog = new Dialog(context);
            dialog.setContentView(R.layout.custom);
            dialog.setTitle("Title...");

            // set the custom dialog components - text, image and button
            TextView text = (TextView) dialog.findViewById(R.id.text);
            text.setText("Android custom dialog example!");
            ImageView image = (ImageView) dialog.findViewById(R.id.image);
            image.setImageResource(R.drawable.ic_launcher);

            Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
            // if button is clicked, close the custom dialog
            dialogButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            dialog.show();

Layout: 布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp" />

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FFF" 
        android:layout_toRightOf="@+id/image"/>/>

     <Button
        android:id="@+id/dialogButtonOK"
        android:layout_width="100px"
        android:layout_height="wrap_content"
        android:text=" Ok "
        android:layout_marginTop="5dp"
        android:layout_marginRight="5dp"
        android:layout_below="@+id/image"
        />

</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM