- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在使用 Flutter 创建一个新应用,并想在初始启动画面上添加自定义图像。
图像出现在初始屏幕上,但是在大约半秒钟内它看起来被拉伸(stretch)了,看起来不太好。
我一直在寻找,但一直找不到有同样问题的人。
有什么想法吗?
我曾尝试使用 mipmap 提供可变大小的图像,但产生了相同的结果。
launch_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/green" />
<item>
<bitmap
android:gravity="center_horizontal"
android:src="@drawable/ic_logo"
android:tileMode="disabled"/>
</item>
</layer-list>
样式.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
<color name="green">#b7dd05</color>
</resources>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flutter_app">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="flutter_app"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
我不介 Intent 像需要一秒钟的渲染时间,但先拉伸(stretch)它并不理想。
最佳答案
您需要提供具有所有可能尺寸(mdpi、hdpi、xhdpi 等)的图像,以便为每个屏幕尺寸提供正确的尺寸并使用此可绘制对象:
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_green_dark" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>
</item>
<item
android:gravity="center"
android:drawable="@drawable/logo_splash">
</item>
</layer-list>
这将是我的风格:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="SplashScreen" parent="AppTheme">
<item name="android:windowBackground">@drawable/splash</item>
<item name="android:windowFullscreen">false</item>
</style>
</resources>
最后这将是我的 AndroidManifest.xml
:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.marianozorrilla">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:theme="@style/SplashScreen">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
所有这些的结果如下:
在我的例子中,logo_splash.png
的大小为 200px-200px。如果您真的想在 DP 中处理大小,您至少需要有 API 23:
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_green_dark" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>
</item>
<item
android:gravity="center"
android:drawable="@drawable/logo_splash"
android:width="100dp"
android:height="100dp">
</item>
</layer-list>
这个看起来像这样:
关于android - Flutter 启动画面在加载时将图像拉伸(stretch)一秒钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56774803/
有什么办法(使用CSS)在最后一步之后将 Sprite 暂停一秒或多秒?我尝试再添加一个步骤或将相同的背景位置从 80% 增加到 100%,但没有成功。 .sprite { animation:
我正在使用 Flutter 创建一个新应用,并想在初始启动画面上添加自定义图像。 图像出现在初始屏幕上,但是在大约半秒钟内它看起来被拉伸(stretch)了,看起来不太好。 我一直在寻找,但一直找不到
我有一个状态: state = { showView: false, } 如何创建一个函数,在调用时将 showView 状态更改为 true 1 秒,然后将其更改回 false? 最佳答案 this
我有一个平滑的滚动效果: jQuery('html,body').animate({scrollTop:scrollTarget}, 1000, "swing"); 它工作正常,但是当按下多个元素时,
我似乎遇到了与我之前发布的问题相同的问题。我想隐藏默认情况下存在的所有 div,只显示一个。然后用户可以单击一个侧面选项卡以显示另一个。问题是 div 在页面加载后仅隐藏一秒钟,但很快就会重新出现。这
我是一名优秀的程序员,十分优秀!