1
votes

In Android App, I have a card game designed with the Linear layout and image buttons. On completing a level in this game I have to do the following things as listed below...

  1. I have to show a dialog like screen which should pop up on middle of screen. This pop-up should hold some background image and buttons on it. The pop-up should fly from bottom-up.

  2. The card game parent screen should be blurred this this pop-up is shown.

I have seen the similar kind of effects in showing ads from Appflood.

Could you please give some suggestion to this effectively.

Parent Screen

enter image description here

With Pop-Up

enter image description here

Thanks in Advance..

2
I tried custom dialog but the UI is not as promising as the Layout in a full screeniappmaker

2 Answers

1
votes

Try that:

Don't use AlertDialog, you can use one normal layout and one normal class. ¿How?

It's easy, you have one class called "FirstActivity.java", and one second class called "SecondActivity.java".

FirstActivity

Designed this class as you like

SecondActivity

You are going to create your own popup with ImageView,Buttons and textviews and you are going to Overlay your layout background.

Popup_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/popup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:src="@drawable/popup_background" />

    <ImageView
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="39dp"
        android:layout_marginTop="72dp"
        android:onClick="go"
        android:src="@drawable/ok" />

    <TextView
    android:id="@+id/question"
    android:text:"level completed"


</RelativeLayout>

manifest

Declare SecondActivity with custom Theme.

......

 <activity
            android:name="com.example.comandero.SecondActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.Overlay" />  
.......

Styles.xml

Add new style for background on your layout.

<style name="Theme.Overlay" parent="android:style/Theme.Translucent">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:background">@android:color/transparent</item>
    </style>

Try it and say me please. If you dont understand something say me.

1
votes

I have a very simple solution (and I tested it - it works pretty well, as illustrated by the pictures I posted).

Imagine you have an invisible (GONE) generic View that covers the whole screen (match_parent, match_parent) and has a reddish semitransparent color.
It would become VISIBLE before showing the Dialog and GONE again after dismissing it.

Since it's GONE, you don't see it and it doesn't waste any space until it becomes VISIBLE.

This approach requires the outer container being a FrameLayout or a RelativeLayout (by setting the View properly: anchoring it to the four Parent's corners).
I used a RelativeLayout - because I really love these containers.

dlg_red_bg.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    android:padding="8dp"
    >
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@android:color/black"
        android:padding="8dp"
        >
        <Button
            android:id="@+id/btnTopLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:background="@drawable/ball"
            android:text="Btn 1"
            android:textColor="@android:color/white"
            android:textSize="24sp"
            android:textStyle="bold"
        />
        <Button
            android:id="@+id/btnTopRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@id/btnTopLeft"
            android:background="@drawable/ball"
            android:text="Btn 2"
            android:textColor="@android:color/white"
            android:textSize="24sp"
            android:textStyle="bold"
        />
        <Button
            android:id="@+id/btnBottomLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/btnTopLeft"
            android:layout_alignParentLeft="true"
            android:background="@drawable/ball"
            android:text="Btn 3"
            android:textColor="@android:color/white"
            android:textSize="24sp"
            android:textStyle="bold"
        />
        <Button
            android:id="@+id/btnBottomRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/btnTopRight"
            android:layout_toRightOf="@id/btnBottomLeft"
            android:background="@drawable/ball"
            android:text="Btn 4"
            android:textColor="@android:color/white"
            android:textSize="24sp"
            android:textStyle="bold"
        />
        <Button
            android:id="@+id/btnDialog"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/ball"
            android:onClick="clickHandler"
            android:text="Dialog"
            android:textColor="@android:color/white"
            android:textSize="24sp"
            android:textStyle="bold"
        />
    </RelativeLayout>
    <View
        android:id="@+id/vwRedOver"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:background="#8f00"
        android:visibility="gone"
    />
</RelativeLayout>

code used to highlight the background

public void clickHandler(final View v)
{
    switch(v.getId())
    {
        case R.id.btnDialog:
        {
            vwRedOver.setVisibility(View.VISIBLE);

            final AlertDialog.Builder bld = new AlertDialog.Builder(this);
            bld.setMessage("Some Message")
            .setCancelable(true)
            .setPositiveButton
            (
                "OK",
                new DialogInterface.OnClickListener()
                {
                    @Override
                    public final void onClick
                    (final DialogInterface dlg, final int id)
                    {
                        vwRedOver.setVisibility(View.GONE);
                        dlg.cancel();
                    }
                }
            )
            .setNegativeButton
            (
                "Cancel",
                new DialogInterface.OnClickListener()
                {
                    @Override
                    public final void onClick
                    (final DialogInterface dlg, final int id)
                    {
                        vwRedOver.setVisibility(View.GONE);
                        dlg.cancel();
                    }
                }
            );
            bld.create().show();
        }
    }
}

result

Before Clicking on "Dialog"

enter image description here

After Clicking on "Dialog"
NOTE 1: It's dark because of the black background
NOTE 2: You see a black border, because I set a padding on the outer RelativeLayout - you can remove it

enter image description here

After Clicking on either "OK" or "Cancel" - returns to the initial state (my Dialog doesn't do anything interesting on OK - It's only for demo purposes)

enter image description here