【问题标题】:How to show the image outside the dialog in android?如何在android中的对话框外显示图像?
【发布时间】:2017-07-03 06:11:12
【问题描述】:

我试图在对话框片段的顶部显示配置文件图像,一半在图像之外。我将示例对话框附在下面,就像这样。并尝试了旧 Stackoverflow 解决方案的所有 FrameLayout 协作,但我无法存档这。请给我正确的解决方案。谢谢你。

更新 我还尝试使 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 布局文件
  • 透明背景我也试过它不工作。请找出我更新的问题。

标签: android layout android-dialogfragment android-framelayout


【解决方案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();

【讨论】:

  • 我试过你的方法。我不知道为什么它对我不起作用..请找出我的更新
  • 它正在工作,它使整个对话框透明。但我想完全为您之前上传的投手透明特定部分。
  • 不希望透明的部分,添加背景色。就像我在我的 LinearLayout 中所做的那样,ID 为 round_dialog_container
【解决方案2】:

这肯定会帮助你尝试这个。

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

在相对布局中使用此代码

【讨论】:

  • 在对话框中不起作用的父布局颜色透明
  • 以编程方式使背景透明,效果很好。
  • 使用此链接制作自定义对话框,您不需要使父布局透明androidtutorials.info/2016/08/…
【解决方案3】:

这可能是最简单的答案?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl_alert_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    android:background="#00FFFFFF">

    <TextView
        android:id="@+id/alert_textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="48dp"
        android:background="#FFF"
        android:paddingHorizontal="20dp"
        android:paddingTop="50dp"
        android:paddingBottom="20dp"
        android:text="Your text goes here.." />

    <ImageView
        android:id="@+id/alert_icon"
        android:layout_width="96dp"
        android:layout_height="96dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/ic_alert_bell" />
</RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-01
    相关资源
    最近更新 更多