Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View outside a Dialogs bounds

I want something like this:

playstorereview

The users profile picture is "popping out" over the dialogs bounds.

I've tried everything: messing with clipping with every possibly combination under the sun, dynamically creating the view after the dialog and adding it to the root content view, using a seperate view and loading that in with Dialog.setCustomTitle(), hacking the Images onDraw() methods and applying all-sorts of bounds/positional hacks --- but no matter what the image always gets clipped and split in half.

I've even gone to the extent of decompiling the Play Store APK and seeing how they did it. Unfortunately the resource files don't give much away and I can't find anything in the Smali.

Can anyone help? Please... :-(

EDIT: I'm just specifically talking about the user profile image at the top of the dialog, not the dialog itself.

like image 363
eth0 Avatar asked Aug 18 '14 10:08

eth0


3 Answers

dialog method:

Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.mhp);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dialog.show();  

mhp.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent" >

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="57dp"
    android:background="#f00"
    android:orientation="vertical" >
</LinearLayout>

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/ic_launcher" />

</RelativeLayout>  

result
Result picture

like image 70
MHP Avatar answered Nov 17 '22 18:11

MHP


It looks like they are just having an rounded Image inside an ImageView and having a Layout with margin from top which is half of the imagesize,

So, if my imagesize is 100px, I should use 50dip to show image centered in all screen

 dialog.xml

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="200dip"
    android:layout_marginTop="50dip" 
    android:background="@android:color/holo_green_dark" >
</LinearLayout>

<ImageView
    android:id="@+id/imageview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:contentDescription="@string/app_name"
    android:src="@drawable/download" />

And then you just have your Dialog with Background Transparent

Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog);
dialog.setCancelable(false);
dialog.getWindow().setBackgroundDrawable(
                                 new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.show();

OUTPUT

enter image description here

like image 28
Lalit Poptani Avatar answered Nov 17 '22 19:11

Lalit Poptani


Just to improve @MHP's answer, you can also add cardView to make the corner of your dialog rounded.

Something like:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/transparent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="57dp"
    android:background="@android:color/transparent"
    android:orientation="vertical">

    <android.support.v7.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/llMainContents"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FAFAFA"
        android:orientation="vertical"
        app:cardCornerRadius="2dp" />
</LinearLayout>

<ImageView
    android:id="@+id/ivIcon"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:padding="8dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:contentDescription="@null"
    android:src="@mipmap/ic_launcher" />

</RelativeLayout>

Result would be: enter image description here

like image 4
mgcaguioa Avatar answered Nov 17 '22 18:11

mgcaguioa