图像始终位于对话框的顶部

时间:2016-05-30 09:04:27

标签: java android android-layout android-alertdialog

我在包含缩放视图的对话框中显示图像。这里放置图像并且缩放工作正常没有任何问题但问题是图像总是放在对话框的顶部,如果我向下滚动它到达中间然后缩放发生。我不想这样,而是图像应该显示在中间,我需要做缩放。

我使用动态imageview和使用chrisbanes photoview库进行缩放。如果我删除库,图像将放在中心。

 @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();
            }
        });

我尝试使用scaletype作为中心的imageview,但是图像放在对话框的顶部。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

使用自定义对话框进行自己的对话框设计

            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();

<强>布局:

<?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>