开发者

How do I center a Theme background image in an Android activity

I've wasted a ton of time on this, and of all the "answers" I've seen searching, none work. Basically, I just want a bitmap to be centered horizontally in the theme, then repeating vertically. No matter what I do, it's always left-aligned. I've tried it in code, and in XML. Here's what I'm using right now:

AndroidManifest.xml

<activity android:name=".MyActivity" android:label="MyActivity"
        android:theme="@style/Them开发者_开发问答eName" />

res/values/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>

res/drawable/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"
/>

To help clarify, I've also tried setting the background to the bitmap in code like so:

Resources r = getResources();
Drawable d = r.getDrawable(R.drawable.xml_bitmap);
getListView().setBackgroundDrawable(d);

This gives the exact same result; leading me to believe something is wrong in the xml_bitmap.xml file. From what I've read in the docs, there's not many other options, and what I have would SEEM to be correct: Drawable Resources

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜