-1

I'm trying to create a Custom Dialog like this, I'm following this answer but changing the layout_gravity to this android:layout_gravity="center_horizontal|top" and it puts on the center of the Dialog as I want, but the thing is that if I want to put the ImageView bigger it destroys the xml, also the Dialog itself it's too small because I only have a TextView and an EditText so what I'm doing wrong?

This is my xml.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" >

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="15dp" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="#fff"
            android:orientation="vertical"
            android:padding="10dp" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Choose the receiver"
                android:textColor="@color/blue"
                android:textSize="16dp" />

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:background="@drawable/edittext_style"
                android:hint="Username"
                android:padding="5dp"
                android:singleLine="true"
                android:textColorHint="@color/wallet_holo_blue_light" />

        </LinearLayout>
    </FrameLayout>

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_gravity="center_horizontal|top"
        android:src="@drawable/icon_mail" />
</FrameLayout>
</FrameLayout>

OUTPUT

enter image description here

Also I've a Drawable to put it on the Dialog to create a border roundered with color and if I put it on LinearLayout it doesn't show up.

This is the rounded_border.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
    <shape android:shape="rectangle" >
        <solid android:color="@color/white" />
        <corners android:radius="12dip" />
        <stroke
            android:width="1dip"
            android:color="@color/wallet_holo_blue_light" />
    </shape>
</item>

If I change the size of the ImageView happens this :

enter image description here

Community
  • 1
  • 1
Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148

2 Answers2

1

You can try this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="vertical">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="30dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
                <View
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="0.5" />
                <View
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="0.5"
                    android:background="#fff" />
            </LinearLayout>
            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_centerInParent="true"
                android:src="@drawable/icon_mail" />
        </RelativeLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="#fff"
            android:orientation="vertical"
            android:padding="8dp">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Choose the receiver"
                android:textColor="@color/blue"
                android:textSize="16dp" />
            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:background="@drawable/edittext_style"
                android:hint="Username"
                android:padding="5dp"
                android:singleLine="true"
                android:textColorHint="@color/wallet_holo_blue_light" />
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

Just important that you keep ImageView width/height (30dp in the example) aligned with parent RelativeLayout height.

andrea.petreri
  • 4,137
  • 2
  • 22
  • 21
0

you need to put some padding in your root frame layout like this:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:padding = "40dp">

also put some negative margin for top in your image view

<ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_gravity="center_horizontal|top"
        android:src="@drawable/icon_mail" 
        android:layout_marginTop="-20dp"/>

adjust the values as it suits.

additionally you are using one unnecessary framelayout, one immediately inside your root layout, you must be getting lint warning about it.

Rahul Tiwari
  • 6,851
  • 3
  • 49
  • 78