我试图在对话框片段的顶部显示配置文件图像,一半在图像之外。我在下面附加了示例对话框,就像那样。并尝试了旧 Stackoverflow 解决方案中的所有 FrameLayout 协作,但我无法存档此内容。请给我正确的解决方案。谢谢。
Updated我还尝试使 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>
在此输入图像描述 https://i.stack.imgur.com/8DDfD.jpg
尝试下面的方法xml
自定义对话框布局.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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)