java - Android 启动画面背景重复模式

标签 java android xml

我正在尝试拥有这个image重复作为我的闪屏的背景。 这是我的 splashscreen.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap
            android:src="@drawable/ic_background_blue"
            android:gravity="center"
            android:tileMode="repeat"/>
    </item>
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/ic_splash_logo"/>
    </item>
</layer-list>

但是图 block android:tileMode="repeat" 似乎被忽略,并且图像被拉伸(stretch)到屏幕的宽高比。

编辑:

android:tileMode="repeat" 适用于 Activity 背景,但我试图在启动屏幕上存档它。 android:gravity="center" 似乎没有任何区别。

我的 Activity 的真实布局是无关紧要的,因为我猜它永远不会被使用。 这是我的 SplashActivity.java 的代码:

package de.ranellstudios.creactivity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {

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

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

我通过向 styles.xml 添加新主题,将 splashscreen.xml 与我的 SplashActivity 连接起来:

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

还有这个

<activity
        android:name=".SplashActivity"
        android:theme="@style/SplashTheme"
        android:screenOrientation="portrait">

到我的 list

我只是想让我在顶部链接的图像在启动画面的背景中重复,而不是拉伸(stretch)到屏幕尺寸。 有什么想法吗?

-----

不知何故,它现在似乎可以工作了,对于给您带来的不便,我们深表歉意,并感谢您的帮助。上面的代码现在是正确的。

最佳答案

看来您没有使用 <layer-list>在你的绘图中。请尝试使用此代码。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap
            android:src="@drawable/ic_background_blue"
            android:tileMode="repeat"/>
    </item>
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/ic_splash_logo"/>
    </item>
</layer-list>

编辑:检查了您提供的图像,其分辨率似乎太大 (2000 x 2000)。可能的解决方案是手动缩小图像或以编程方式设置图像背景。

关于java - Android 启动画面背景重复模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46364240/

相关文章:

java - 如何防止后退按钮直到确认消息?

xml - Powershell-XML在现有部分中插入新行

html - XML 文件仅显示 DTD 而非 XSLT 的数据

android xml Textview文本属性不能取 '<'作为值

java - 带处理程序的顺序倒计时器将无法正确更新 textView

java - 在没有 keyPressed/Released 事件的情况下检查键的状态

java - 如何从链表中删除节点

android - getResources(R.string.hello_world) 和 R.string.hello_world 的区别

android - 是否可以从广播接收器启动 Intent ?

android - 想为Android开发。有一些基本的非常见问题