android - 如何在android中显示对话框外的图像?

标签 android layout android-dialogfragment android-framelayout

我试图在对话框 fragment 的顶部显示个人资料图像,一半在图像之外。我在下面附上示例对话框,就像那样。并尝试了旧 Stackoverflow 解决方案中的所有 FrameLayout 协作,但我无法存档这。请给我正确的解决方案。谢谢。

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

最佳答案

试试下面的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();

关于android - 如何在android中显示对话框外的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44878784/

相关文章:

android - Android 兼容性 API 的 PreferenceFragment 替代方案?

android - 如何在 sencha touch 中为不同的屏幕分辨率添加图像?

android - 意外标记(使用 ';' 分隔同一行上的表达式)

java - 自动解析 Android Studio 中 XML 布局文件中的所有红色下划线?

javascript - html 可以工作,但 javascript 在 android 版本 4.4 中不工作

javascript - Magento 1 - 通过布局更新 xml 代码将内联 javascript 添加到产品页面

css - div 在调整大小时改变位置

android - v7 支持 23.0.1 崩溃 : AppCompatButton. setBackgroundDrawable

java - 使用回调在 DialogFragment 中传回数据(android)

android - 从 DialogFragment 设置状态栏颜色