如何在Xamarin中设置DialogFragment大小?

时间:2016-07-30 21:31:19

标签: xamarin size android-dialogfragment

我正在尝试设置自定义DialogFragment的大小。我正在尝试这样的事情:

Select Country , Sum(Winners) as Winners, Sum(RunnerUp)  as RunnerUp 
FROM
(
Select Count as Winners , 0 as RunnerUp, Country from Winners 
Union ALL
Select 0  as Winners , Count as RunnerUp, Country from RunnerUp
) a
Group By Country 

但它不起作用。我没有收到任何错误。你可以帮帮我吗?

3 个答案:

答案 0 :(得分:0)

设置根元素的布局参数:

int width = this.Resources.DisplayMetrics.WidthPixels;
int height = this.Resources.DisplayMetrics.HeightPixels
rootLayout.setLayoutParams (new LinearLayout.LayoutParams (width, height));

答案 1 :(得分:0)

您必须在OnResume中设置值(这很不直观,但是效果很好)。我也有尊重密度的代码,无论密度如何,都可以严格控制尺寸。

    public override void OnResume()
    {
        base.OnResume();

        var window = Dialog.Window;
        var requestedWidth = (int)(350 * (this.Resources.DisplayMetrics.Density));
        var requestedHeight = (int)(175 * (this.Resources.DisplayMetrics.Density));

        window.SetLayout(requestedWidth, requestedHeight);
        window.SetGravity(GravityFlags.Center);           
    }

答案 2 :(得分:-1)

    public override void OnActivityCreated(Bundle savedInstanceState)
    {
        this.Dialog.Window.RequestFeature(WindowFeatures.NoTitle);
        this.Dialog.Window.SetGravity(GravityFlags.Center);
        base.OnActivityCreated(savedInstanceState);
        int Width = (Resources.DisplayMetrics.WidthPixels) - 150;
        int Height = (Resources.DisplayMetrics.HeightPixels) - 70;
        this.Dialog.Window.Attributes.Width = Width;
        this.Dialog.Window.Attributes.Height = Height;
    }