如何在Xamarin Android中在屏幕上显示完整尺寸的视图? [英] How to display a View in Full Size on screen in Xamarin Android?

查看:221
本文介绍了如何在Xamarin Android中在屏幕上显示完整尺寸的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法设置与Display Size匹配的View Size,下面是代码,它是Transparent View

I am unable to set the View Size matching the Display Size, below is the code, it is a Transparent View

 TestView testView;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        testView = new TestView(this);
        SetContentView(testView);

    }

应用运行时ViewDefault Heightheight=1206 但是显示高度"是1280,我已经使用以下方法将视图大小"设置为与屏幕大小"匹配,但是没有一种方法

The Default Height of the View when the app runs is height=1206 but the Display Height is 1280, i have used the following methods to set the View Size match the Screen Size, but none works

不起作用

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    testView = new TestView(this);
    IWindowManager window = null;
        window = this.Application.GetSystemService(Context.WindowService).JavaCast<IWindowManager>();
        Display defaultDisplay = window.DefaultDisplay;
        DisplayMetrics display = new DisplayMetrics();
        defaultDisplay.GetRealMetrics(display);
        int width = display.WidthPixels;
        int height = display.HeightPixels;
        RelativeLayout.LayoutParams parms = new 
                       RelativeLayout.LayoutParams(width, height);
        testView.LayoutParameters = parms;
    SetContentView(testView);

}

结果:

不起作用:

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    testView = new TestView(this);
    SetContentView(testView);
    if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
        {

            Window.SetFlags(WindowManagerFlags.LayoutNoLimits,
                              WindowManagerFlags.LayoutNoLimits);
        }

}

<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>

结果:

如何将显示高度"设置为视图"?

How to set the Display height to the View?

推荐答案

您需要在清单文件中声明其活动应为全屏显示:

You need to declare it in your manifest file that your activity should be of full screen:

<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

如果要通过代码获取它,只需在活动的onCreate方法中使用以下几行即可:

And if you want to get it through code just use these lines in your activity's onCreate method:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

或将以下行添加到style.xml文件中

Or Add the below line to the style.xml file

 //your theme
 <style name="Theme.AppCompat.Transparent.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
      //XML lines for full screen
      <item name="android:windowNoTitle">true</item>
      <item name="android:windowFullscreen">true</item>
 </style>

要获得更多帮助,请查看以下答案: Android中的全屏活动?

For more help take a look at this answer: Fullscreen Activity in Android?

这篇关于如何在Xamarin Android中在屏幕上显示完整尺寸的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆