1

I want to code this dialog layout: http://fooh.pl/pokaz/348687655.png

Green containner is in orange container. At the top of the dialogue is TextView. In the upper right corner is a button.

I know the types of layouts, but I failed.

Can anyone help me? Please.

kamilf
  • 157
  • 1
  • 3
  • 15
  • No offence, but how in the world does a question like this get an upvote? Please provide code that you have tried and we can help you learn. – codeMagic Apr 01 '13 at 20:52
  • I'm not lying. It's my code: http://pastebin.com/cbSrk095 It works, but I can't add to this layout close button. – kamilf Apr 01 '13 at 21:12

2 Answers2

0

Here you go:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@drawable/rounded_orange">

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_margin="8dp"
    android:text="Text"/>

  <RelativeLayout 
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="32dp"
    android:background="@drawable/rounded_green">
  </RelativeLayout>

</RelativeLayout>

Where the drawables (only green shown here) are laid out like this:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
  <solid android:color="#0F0"/>
  <corners android:radius="16dp"/>
</shape>

If you need help applying the custom layout.xml file to your dialog, read up on 'Creating a Custom Dialog' in the official docs of Dialog.

klmprt
  • 651
  • 6
  • 7
  • Thanks! :) And now, can set background image for these containers? (.png or .9.png) – kamilf Apr 01 '13 at 20:59
  • Yes you could also set the background of each RelativeLayout with a 9-patch if you prefer that over using an xml-defined drawable. If this answers your question, please accept my answer by clicking the check mark under the down arrow. – klmprt Apr 01 '13 at 21:03
  • So how to set 9path image in this orange container? And how to set button on this layout? – kamilf Apr 01 '13 at 21:15
  • Add your your_image.9.png file to res/drawable and reference it in xml as @drawable/your_image – klmprt Apr 01 '13 at 21:58
0

Here's a link to the documentation with good examples or how to create a dialog fragment based on a layout.

And here is a good SO answer that shows how to inflate a layout for use in a dialog fragment.

Community
  • 1
  • 1
Jim
  • 6,753
  • 12
  • 44
  • 72