Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-图层列表中的相对位图大小_Android_Xamarin_Android Bitmap_Layer List - Fatal编程技术网

Android-图层列表中的相对位图大小

Android-图层列表中的相对位图大小,android,xamarin,android-bitmap,layer-list,Android,Xamarin,Android Bitmap,Layer List,我正在尝试在Xamarin中为Android应用程序制作一个初始屏幕。我在drawable文件夹中创建了xml文件,该文件用作主题的背景,并使用自定义活动呈现 我成功地做到了这一点。图像是固定大小的,其中心位于视图的中间。非常适合纵向和横向模式 这是splash_screen.xml的代码: <?xml version="1.0" encoding="UTF-8" ?> <layer-list xmlns:android="http://schemas.android.com/

我正在尝试在Xamarin中为Android应用程序制作一个初始屏幕。我在drawable文件夹中创建了xml文件,该文件用作主题的背景,并使用自定义活动呈现

我成功地做到了这一点。图像是固定大小的,其中心位于视图的中间。非常适合纵向和横向模式

这是splash_screen.xml的代码:

<?xml version="1.0" encoding="UTF-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <color android:color="@color/launcher_background"/>
  </item>
  <item
    android:height="500px"
    android:width="500px"
    android:gravity="center">
    <bitmap
        android:src="@drawable/ic_launcher_rounded"/>
        android:gravity="fill"/>
  </item>
</layer-list>

android:gravity=“fill”/
这是一个主题:

<style name="SplashTheme">
  <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="android:windowNoTitle">true</item>  
        <item name="android:windowFullscreen">true</item>
</style>

@可拉伸/飞溅屏幕
真的
真的
我想要实现的是,使图像相对于屏幕大小,因此宽度和高度在纵向模式下为宽度的60%,在横向模式下为高度的60%


这是否可行,以及如何实现?

当屏幕在纵向模式和横向模式之间切换时,您可以尝试使用两个不同大小的图像进行切换。因为更改高度或宽度会影响图像显示效果

同时,我们可以使用图层列表将根布局设置为背景,而不是将其用作主题中的背景

所以你可以这样做:

activitylayout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@drawable/splash_screen"
android:id="@+id/root_layout"
android:layout_height="match_parent">
<!--   other code  -->
</LinearLayout>

当屏幕在纵向模式和横向模式之间切换时,您可以尝试使用两个大小不同的图像进行切换。因为更改高度或宽度会影响图像显示效果

同时,我们可以使用图层列表将根布局设置为背景,而不是将其用作主题中的背景

所以你可以这样做:

activitylayout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@drawable/splash_screen"
android:id="@+id/root_layout"
android:layout_height="match_parent">
<!--   other code  -->
</LinearLayout>

请您发布
启动屏幕的完整代码
?您的代码有一些问题。它是完整的代码,但颜色标记的格式不正确。现在是正确的。您可以发布
启动屏幕的完整代码吗?您的代码有一些问题。它是完整的代码,但颜色标记的格式不正确。现在是正确的。最大尺寸,取决于屏幕分辨率,纵向和横向的尺寸相同。图像的宽度和高度是相同的,在纵向模式下它应该是宽度的60%,在横向模式下它应该是高度的60%(肖像.宽度==横向.高度)。很抱歉这么晚才回复,你的问题解决了吗?没有。如果你有更多的想法,我很想听听。最大尺寸,取决于屏幕分辨率,纵向和横向的尺寸相同。图像的宽度和高度是相同的,在纵向模式下它应该是宽度的60%,在横向模式下它应该是高度的60%(肖像.宽度==横向.高度)。很抱歉这么晚才回复,你的问题解决了吗?没有。如果你有更多的想法,我很想听听。谢谢
LinearLayout root_layout;

root_layout = FindViewById<LinearLayout>(Resource.Id.root_layout);
      public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig)
    {
        base.OnConfigurationChanged(newConfig);
        LayerDrawable layerDrawable = (LayerDrawable)this.GetDrawable(Resource.Drawable.splash_screen);
        if (newConfig.Orientation == Android.Content.Res.Orientation.Portrait)
        {
            System.Diagnostics.Debug.WriteLine("Portrait...");
            Drawable drawable = this.GetDrawable(Resource.Drawable.agirl);
            layerDrawable.SetDrawableByLayerId(Resource.Id.layer_photo, drawable);

            root_layout.SetBackgroundDrawable(layerDrawable);              
        }
        else if (newConfig.Orientation == Android.Content.Res.Orientation.Landscape)
        {
            System.Diagnostics.Debug.WriteLine("Landscape...");
            Drawable drawable = this.GetDrawable(Resource.Drawable.img123);
            layerDrawable.SetDrawableByLayerId(Resource.Id.layer_photo, drawable);

            root_layout.SetBackgroundDrawable(layerDrawable);
        }
    }