如何在Android对话框外显示图像? [英] How to show the image outside the dialog in android?

查看:123
本文介绍了如何在Android对话框外显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在对话框片段的顶部显示配置文件图像,图像的一半在外面.然后我在下面附加示例对话框.并尝试了来自旧Stackoverflow解决方案的所有FrameLayout协作,但是我无法归档这.请给我正确的解决方案.谢谢你.

I trying to show the profile image in topside of the dialog fragment with half outside the image.and i attach the sample dialog in below, like that.And tried all FrameLayout collaboration from old Stackoverflow solutions, But i cant able to archive this. Please give me correct solution. Thankyou.

已更新 我还尝试使ImageView父级布局透明,但在对话框显示后无法使用.我在下面附加我的xml和结果屏幕截图.

Updated I also tried to make transparent the ImageView parent layout but it's not working in after dialog show. i attach my xml and result screen shot below.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_item"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
    android:id="@+id/imageshow"
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <View
        android:id="@+id/imagePadding"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@android:color/transparent" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/imagePadding"
        android:background="#ff0000"></LinearLayout>

    <ImageView
        android:id="@+id/info_profile"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerHorizontal="true"
        android:src="@drawable/technician_pitcher" />
</RelativeLayout>

在此处输入图像描述

推荐答案

尝试以下xml

custom_dialog_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl_dialog_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="16dp">

<View
    android:id="@+id/imagePadding"
    android:layout_width="match_parent"
    android:layout_height="70dp" />

<LinearLayout
    android:id="@+id/round_dialog_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/imagePadding"
    android:background="#ffffff"
    android:gravity="bottom"
    android:orientation="vertical">

    <View
        android:id="@+id/imagePadding2"
        android:layout_width="match_parent"
        android:layout_height="70dp" />

</LinearLayout>

<ImageView
    android:id="@+id/dialog_image"
    android:layout_width="140dp"
    android:layout_height="140dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:src="@mipmap/ic_launcher" />

</RelativeLayout>

在显示对话框时,请遵循以下代码:

And when you are displaying your dialog, follow the code below:

     Dialog dialog = new Dialog(MainActivity.this);
            dialog.setContentView(R.layout.custom_dialog_layout);
            //The line below is important
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.show();

这篇关于如何在Android对话框外显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆