Custom Dialog not centered

SiflouSiflou USMember ✭✭

Hey Guys,

I'm creating a custom dialog, so I have a class which derives from dialog and I'm setting the contentview to my view. The problem is that I want my dialog to be centered in the screen, but it is not centered vertically, only horizontally. Here are my layout and my Dialog Class. If some one has an idea, it would be great.

Thanks a lot for your time :)

Claude

`using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using global::Android.Graphics.Drawables;

using MaitreD_Dashboard.Core.AlertWS;

namespace MaitreD_Dashboard.Android
{
class NotificationDialog : Dialog
{
#region PRIVATE_MEMBERS

    Activity mActivity;
    Dialog mDialog;
    Button mBtnOk;
    RelativeLayout mBtnDelete;
    TextView mLblTitle;
    TextView mLblDate;
    TextView mLblMessage;
    RelativeLayout mRlBaseContainer;
    List<LinearLayout> mLlRestaurants;

    #endregion

    #region CONSTRUCTORS

    public NotificationDialog(Activity aActivity,int theme) :base(aActivity, theme)
    {
        mActivity = aActivity;
    }

    #endregion

    #region ANDROID_METHODS

    protected override void OnCreate (Bundle savedInstanceState)
    {
        base.OnCreate (savedInstanceState);
        SetContentView (Resource.Layout.NotificationDialog);
        Window.SetBackgroundDrawable (new ColorDrawable (global::Android.Graphics.Color.Transparent));
        /*Window.SetLayout (LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
        Window.SetGravity(GravityFlags.Center);*/

        //Get contrtols
        mRlBaseContainer    = FindViewById<RelativeLayout> (Resource.Id.rlBaseContainer);
        mBtnOk              = FindViewById<Button> (Resource.Id.btnOk);
        mBtnDelete          = FindViewById<RelativeLayout> (Resource.Id.rlBtnDelete);
        mLblTitle           = FindViewById<TextView> (Resource.Id.lblTitle);
        mLblDate            = FindViewById<TextView> (Resource.Id.lblDate);
        mLblMessage         = FindViewById<TextView> (Resource.Id.lblMessage);
        mRlBaseContainer.LayoutParameters = new ViewGroup.LayoutParams (200, 200);
        //Events
        mBtnDelete.Click -= OnBtnDeleteClick;
        mBtnDelete.Click += OnBtnDeleteClick;
        mBtnOk.Click -= OnBtnOkClick;
        mBtnOk.Click += OnBtnOkClick;

        //Test data
        mLblTitle.Text = "Title";
        mLblDate.Text = "Date";
        mLblMessage.Text = "Message";

    }

    #endregion


    #region BUTTONS_CLICK

    void OnBtnOkClick(object sender, EventArgs e)
    {
        Console.Write ("OK");
        Dismiss ();
    }

    void OnBtnDeleteClick(object sender, EventArgs e)
    {
        Console.Write ("Detel");
        //
        AlertDialog confirmation = new AlertDialog.Builder (mActivity).Create ();

        //
        confirmation.SetTitle (mActivity.GetString (Resource.String.deleteTitle));

        //
        confirmation.SetMessage (mActivity.GetString (Resource.String.deleteMessage));

        //
        confirmation.SetCancelable (true);

        //
        confirmation.SetButton (mActivity.GetString (Resource.String.yes), OnBtnDeleteYesClick);
        confirmation.SetButton2 (mActivity.GetString (Resource.String.no), OnBtnDeleteNoClick);

        //
        confirmation.Show ();
    }

    void OnBtnDeleteYesClick(object sender, DialogClickEventArgs e)
    {
        Dismiss ();
    }

    void OnBtnDeleteNoClick(object sender, DialogClickEventArgs e)
    {
    }

    #endregion
}

}

`

Here is my layout :

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:id="@+id/rlBaseContainer"> <RelativeLayout android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/relativeLayout7" android:layout_gravity="center" android:layout_centerInParent="true"> <LinearLayout android:orientation="vertical" android:minWidth="25px" android:minHeight="25px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/linearLayout11" android:layout_centerInParent="true" android:background="@drawable/bkg_AlertNotification"> <LinearLayout android:orientation="horizontal" android:minWidth="25px" android:minHeight="25px" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <RelativeLayout android:minWidth="25px" android:minHeight="25px" android:id="@+id/relativeLayout6" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:orientation="horizontal" android:minWidth="25px" android:minHeight="25px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/linearLayout10"> <LinearLayout android:orientation="vertical" android:minWidth="25px" android:minHeight="25px" android:id="@+id/linearLayout4" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.03" /> <RelativeLayout android:minWidth="25px" android:minHeight="25px" android:id="@+id/relativeLayout1" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.94"> <LinearLayout android:orientation="horizontal" android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/baseLL"> <LinearLayout android:orientation="vertical" android:minWidth="25px" android:minHeight="25px" android:id="@+id/linearLayout7" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.9" android:weightSum="4"> <RelativeLayout android:minWidth="25px" android:minHeight="25px" android:layout_width="fill_parent" android:layout_height="0dp" android:id="@+id/relativeLayout3" android:layout_weight="1"> <TextView android:text="Text" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/lblTitle" android:layout_centerInParent="true" /> </RelativeLayout> <RelativeLayout android:minWidth="25px" android:minHeight="25px" android:layout_width="fill_parent" android:layout_height="0dp" android:id="@+id/relativeLayout4" android:layout_weight="1"> <TextView android:text="Text" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/lblDate" android:layout_centerVertical="true" /> </RelativeLayout> <RelativeLayout android:minWidth="25px" android:minHeight="25px" android:layout_width="fill_parent" android:layout_height="0dp" android:id="@+id/relativeLayout4" android:layout_weight="1"> <TextView android:text="Text" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/lblMessage" android:layout_centerVertical="true" /> </RelativeLayout> <RelativeLayout android:minWidth="25px" android:minHeight="25px" android:layout_width="fill_parent" android:layout_height="0dp" android:id="@+id/relativeLayout5" android:layout_weight="1"> <Button android:text="@string/ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btnOk" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="@drawable/BtnSignup" /> </RelativeLayout> </LinearLayout> <LinearLayout android:orientation="horizontal" android:minWidth="25px" android:minHeight="25px" android:layout_width="0dp" android:layout_height="fill_parent" android:id="@+id/linearLayout9" android:layout_weight="0.1" /> </LinearLayout> </RelativeLayout> <LinearLayout android:orientation="vertical" android:minWidth="25px" android:minHeight="25px" android:id="@+id/linearLayout6" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.03" /> </LinearLayout> <RelativeLayout android:minWidth="25px" android:minHeight="25px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/rlBtnDelete" android:layout_alignParentTop="true" android:layout_alignParentRight="true"> <LinearLayout android:orientation="vertical" android:minWidth="25px" android:minHeight="25px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/llBtnDelete" android:layout_centerInParent="true" android:background="@drawable/BtnHeaderLittleTrash" /> </RelativeLayout> </RelativeLayout> <LinearLayout android:orientation="horizontal" android:minWidth="25px" android:minHeight="25px" android:id="@+id/linearLayout3" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> </RelativeLayout> </RelativeLayout>

Sign In or Register to comment.