1

I need to have a dialog (it's a game dialog) where buttons are at the lower corners of the dialog. Not inside the dialog but rather on the very corners (i.e. part of the button will reside over the dialog and the part will be outside of it).

Taras
  • 488
  • 6
  • 21
  • Are you using AlertDialog.Builder for your dialog? – Josh Jan 16 '12 at 14:39
  • I tried builders and layouts. I don't have a restriction on the mechanism. I'll use whatever will help me to achieve the desired look – Taras Jan 16 '12 at 14:47

2 Answers2

2

First, as far as I know you can't move layout children outside their parent.

I've never tried exactly what you're going for, but I think it can be done. The trick would be to go with an activity with a dialog theme (you can find examples of these on the developer site or the API demos). Make sure your layout's root node has width and height set to wrap_content. Your root layout should be a RelativeLayout and have NO background (android:background="#0000").

Next, add another layout to your root node (FrameLayout would probably work) with a custom drawable for a background (or use the one that the default dialog uses from the framework) and width and height set to fill_parent or match_parent. Set android:padding to some dip value which pulls the background in from the edge of the dialog.

The only thing left to do would be to add your other layout elements to the root node. The FrameLayout will be drawn beneath everything else, and the padding will create the illusion of borders which do not encompass your UI.

Update Yikes, just tried the above with good and bad results. First, you'll definitely want to look at the "Custom Dialog" example from the API demo, which makes use of:

Create an activity which uses the above xml layout file, and set the style for the activity to Theme.CustomDialog that you defined in xml/styles.xml. This will get you a red background for your activity. You can then edit the filled_box shape file to just have one background attribute set to invisible ("#0000"). The result should be an dialog-shaped activity with no background.

Next I tried to hack a background using my thoughts from above. The idea should be that there's a phony background drawn behind the other UI elements which does not encompass them, so it could be "shrunk" using layout_margin and not affect them. The problem here is that the phony background needs to have width and height set to relative to the other UI elements, so it sort of HAS to encompass them, so it can properly measure its own width and height relative to them.

So I think the solution could be to do most of what I've said above, except don't try the phony background thing. Just use a 9-patch drawable for your root layout background, and shrink the edges of your background to be drawn farther in than your content. You'd still use the custom theme stuff from above with an invisible window theme.

Josh
  • 10,618
  • 2
  • 32
  • 36
1

Here is a sample layout which i tried:

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

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 >
<FrameLayout
android:orientation="vertical"
android:id="@+id/ll1" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:drawable/dialog_frame">
</FrameLayout>
<Button android:layout_width="wrap_content"
 android:id="@+id/button1" 
 android:layout_height="wrap_content"
 android:layout_marginTop="35dp"
 android:layout_centerHorizontal="true"
  android:text="Button"></Button>
</RelativeLayout>

here is the screenshot: layout sample

hope u get the hint , goodluck

Pratik Bhat
  • 7,166
  • 2
  • 35
  • 57
  • Tried that and works ok, except i got the dialog border encompassing all drawn above. I used tips from [this topic](http://stackoverflow.com/questions/1883425/android-borderless-dialog) to fix this. Thanks for the help! – Taras Jan 17 '12 at 09:04