Skip to content Skip to sidebar Skip to footer

How To Show The Image Outside The Dialog In Android?

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 collab

Solution 1:

Try the below xml

custom_dialog_layout.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns: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"><Viewandroid:id="@+id/imagePadding"android:layout_width="match_parent"android:layout_height="70dp" /><LinearLayoutandroid: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"><Viewandroid:id="@+id/imagePadding2"android:layout_width="match_parent"android:layout_height="70dp" /></LinearLayout><ImageViewandroid: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:

Dialogdialog=newDialog(MainActivity.this);
            dialog.setContentView(R.layout.custom_dialog_layout);
            //The line below is important
            dialog.getWindow().setBackgroundDrawable(newColorDrawable(Color.TRANSPARENT));
            dialog.show();

Solution 2:

This will definitely help you try this.

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

use this code inside Relative layout

Solution 3:

This could be the simplest anwer?

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns: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"><TextViewandroid: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.." /><ImageViewandroid: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>

Post a Comment for "How To Show The Image Outside The Dialog In Android?"