如何在Android活动中居中主题背景图像

AC2*_*2MO 5 android android-layout

我浪费了大量的时间,而且我所看到的所有"答案"都没有用.基本上,我只想让一个位图在主题中水平居中,然后垂直重复.无论我做什么,它总是左对齐.我在代码和XML中尝试过它.这就是我现在正在使用的:

AndroidManifest.xml中

<activity android:name=".MyActivity" android:label="MyActivity"
        android:theme="@style/ThemeName" />
Run Code Online (Sandbox Code Playgroud)

RES /值/ styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="ThemeName" parent="android:Theme">
        <item name="android:windowBackground">@drawable/xml_bitmap</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

RES /抽拉/ xml_bitmap.xml

<?xml version="1.0" encoding="UTF-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/png_image"
    android:tileMode="repeat"
    android:gravity="center_horizontal"
/>
Run Code Online (Sandbox Code Playgroud)

为了帮助澄清,我还尝试在代码中将背景设置为位图,如下所示:

Resources r = getResources();
Drawable d = r.getDrawable(R.drawable.xml_bitmap);
getListView().setBackgroundDrawable(d);
Run Code Online (Sandbox Code Playgroud)

这给出了完全相同的结果; 让我相信xml_bitmap.xml文件中有问题.从我在文档中看到的内容来看,没有太多其他选项,我所拥有的SEEM是正确的:Drawable Resources