1

我试图在对话框片段的顶部显示配置文件图片,其中一半是在image.and之外的,我在下面附加了示例对话框,就像那样。并尝试了所有来自旧的Stackoverflow解决方案的FrameLayout协作,但是我无法将其归档。请给我正确的解决方案。谢谢。如何在android中的对话框外显示图像?

enter image description here

更新 我还试图使透明的ImageView的父布局,但之后对话框显示不工作英寸我附上我的xml和下面的结果屏幕截图。

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

enter image description here

+0

内进行对话BG透明。然后按你想要的那样画出它。 –

+0

发布您的XML布局文件的对话框 –

+0

透明的背景也我试过它不工作。请找出我最新的问题。 –

回答

1

尝试以下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> 

而且当你显示你的对话框,请按照下面的代码:

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

我试过你的方式。我不知道为什么它不适合我.. plz找出我的更新 –

+0

好吧我已经更新了我的答案,看看! –

+0

它正在工作,它透明的整个对话框。但我想透明的特定部分准确地为您以前上传的投手。 –

0

这一定会帮你试试这个。

<RelativeLayout 
    android:layout_width="300dp" 
    android:layout_height="300dp" 
    android:layout_centerInParent="true"> 
    <View 
     android:layout_width="match_parent" 
     android:id="@+id/li1" 
     android:background="@android:color/transparent" 
     android:layout_height="50dp" 
     android:orientation="horizontal"> 
    </View> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_below="@+id/li1" 
     android:background="#ff0000" 
     android:layout_height="match_parent"> 

    </LinearLayout> 
    <ImageView 
     android:layout_width="100dp" 
     android:layout_centerHorizontal="true" 
     android:background="#ffd500" 
     android:layout_height="100dp" /> 

</RelativeLayout> 

使用此代码相对布局

+0

父级布局颜色透明在对话框中不工作 –

+0

为了以编程方式制作透明的背景,这很好。 –

+0

使用此链接进行自定义对话框,你不需要使父级布局透明http://www.androidtutorials.info/2016/08/android-custom-poup-dialog.html#more – Akp