0

I have the following layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="320dp"
    android:layout_height="wrap_content"
    android:background="@color/md_white_1000"
    android:layout_gravity="center_horizontal"
    android:paddingBottom="16dp">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_gravity="center">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/bg_kids_popup"
            android:scaleType="fitXY"
            />


        <ImageView
            android:layout_marginTop="16dp"
            android:id="@+id/dialog_kids_image"
            android:src="@drawable/pic_baby_crown"
            android:layout_gravity="center_horizontal"
            android:layout_width="120dp"
            android:layout_height="120dp" />


    </FrameLayout>

    <TextView
        android:layout_marginTop="24dp"
        android:id="@+id/dialog_kids_hi"
        android:text="Oii,\nApresente seus pequenos pra gente!"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:textSize="24sp"
        android:textColor="@color/dinda_color_dark"
        android:gravity="center"
        android:textStyle="bold"
        />

    <TextView
        android:id="@+id/dialog_kids_custom_offers"
        android:layout_marginTop="10dp"
        android:text="Cadastre as crianças para quem você compra na Dinda e recebe ofertas personalizadas ;)"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        android:textSize="13sp"
        />

    <Button
        android:id="@+id/dialog_kids_go_kids"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="16dp"
        android:background="@drawable/shape_oval_kids_button"
        android:layout_marginLeft="28dp"
        android:layout_marginRight="28dp"
        android:text="@string/kids_register_now"
        android:textAllCaps="true"
        android:textAppearance="@style/Widget.AppTheme.Button.TextAppearance"
        android:textColor="@color/md_white_1000"
        android:textSize="14sp" />

</LinearLayout>

Looking the image below, the grey area is not fulfilling the entire dialog. I tried setting the FrameLayout to match_parentbut doing this, the dialog gets stretched in the screen, without the paddings at left and right.

How should I proceed to keep the dialog padding (screen - dialog) but make the background image to fulfill the inner area ?

Thanks !

enter image description here

Cœur
  • 37,241
  • 25
  • 195
  • 267
Leonardo
  • 3,141
  • 3
  • 31
  • 60

2 Answers2

0

the only issue i can see is you have hardcoded width for FrameLayout try this android:layout_width="match_parent"

  • If I do this, the dialog gets stretched and fulfill the entire screen. – Leonardo May 25 '16 at 17:14
  • You can control dialog dimensions using style check this http://stackoverflow.com/questions/6624480/how-to-customize-the-width-and-height-when-show-an-activity-as-a-dialog –  May 26 '16 at 06:33
0

it seem this happen cause of your root view has fix width android:layout_width="320dp" change it match_parent , and change framelayout to match_parent as well or do it pragmatically

 FrameLayout fl = (FrameLayout) findViewById(R.id.frameLayout);
    fl.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

if you face any trouble with stretch image

android:scaleType="centerCrop" 

I hope this help you

Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
  • The problem doind this is that the dialog loses it's outer margins (padding), getting stretched. I need the margin size to be exact like in the question image. Doing what you said, brings me to this: http://i.imgur.com/olCL0cM.png – Leonardo May 25 '16 at 17:26
  • did you fix your issue ? may be you need android:adjustViewBounds="true" in your image view – Mina Fawzy Jun 16 '16 at 10:48