gpt4 book ai didi

java - Android - 如何将我的初始屏幕图形显示得更大?

转载 作者:搜寻专家 更新时间:2023-11-01 08:38:04 27 4
gpt4 key购买 nike

我似乎无法弄清楚如何让我的初始屏幕图形显示得更大,有人可以帮忙吗?我的图像是一个 288x69 像素的 png 文件,但在 Android 设备上它呈现得很小,我不知道如何更改它。我的启动画面完美无缺,除了图像尺寸。它是用 android:drawable 在 xml 中绘制的,但无论我尝试什么,它都不会渲染得更大。任何提示将非常感谢!

图像添加到android studio res/mipmap/..下,导入android studio后xxxhdpi版本为192 x 192像素。

要创建启动画面,在我的 AndroidManifest.xml 中有以下内容:

        <activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

在 res/drawable 下,我创建了 background_splash.xml,其中包含:

<?xml version="1.0" encoding="utf-8"?>

<item
android:drawable="@color/white"
android:id="@+id/splashDrawable"
android:layout_width="match_parent"
android:layout_height="match_parent"/>


<item>
<bitmap
android:gravity="center"
android:src="@mipmap/my_logo"
android:id="@+id/splashLogo"/>

</item>

在我的 java 文件夹中,我有 SplashActivity.java 和以下内容,这会导致启动在应用程序加载完成时消失:

public class SplashActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}

在我的 styles.xml 文件中我有这个:

  <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>

最佳答案

对于正在阅读本文并遇到同样问题的任何其他人;

我的最终解决方案是使用/res/drawable 文件夹而不是/res/mipmap。在您的硬盘上,在 android studio 之外,浏览到 app/src/main/res 并确保您有名为 drawable-hdpi、drawable-mdpi、drawable-xhdpi 和 drawable-xxhdpi 的文件夹。手动将图像调整为您认为适合每种尺寸的任何尺寸,然后将图像复制进去。现在返回 android studio,图像应该显示在 android studio 的/res/drawable 区域中。现在我更改我的 res/drawable/background_splash.xml 文件以引用 @drawable 而不是 @mipmap ,如下所示,很快它就可以工作了!我只测试了几台设备,但图像看起来不错。我不是 100% 确定它选择了正确的分辨率,但它看起来很合适。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:drawable="@color/white"
android:id="@+id/splashDrawable"
android:layout_width="10px"
android:layout_height="10px"/>


<item>
<bitmap
android:gravity="center"
android:width="10px"
android:height="10px"
android:src="@drawable/bodysite_logo"
android:id="@+id/splashLogo"/>

</item>

关于java - Android - 如何将我的初始屏幕图形显示得更大?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35050638/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com