2012-10-22 127 views
0

我想创建一个具有重复背景图像的布局。我搜索并来自this tutorial 但似乎不适合我! 以下展会activity_main.xml中背景重复图像不起作用

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/backrepeat" 
android:gravity="center_horizontal" 
android:orientation="vertical" > 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" /> 

</LinearLayout> 

,这是backrepeat.xml

<?xml version="1.0" encoding="utf-8"?> 
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
android:dither="true" 
android:src="@drawable/bg" 
android:tileMode="repeat" /> 

也把backrepeat.xml在绘制文件夹中。 我应该添加还是删除一些代码?

感谢

+0

不知道我得到正确你的问题,所以你希望您的背景变得生动。如果是这样,请尝试[AnimationDrawable](http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html) – Wenhui

+0

您的'drawable/bg'图像有多大? – slybloty

+0

bg图像的大小是3px中的3px.does它的重要性? – IndieBoy

回答

0

好吧,这是我在我的应用程序已经有了。它包括一个黑客来防止ListView在滚动时变黑。

绘制/ app_background.xml:

<?xml version="1.0" encoding="utf-8"?> 
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
     android:src="@drawable/actual_pattern_image" 
     android:tileMode="repeat" /> 

值/ styles.xml:

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

    <style name="app_theme" parent="android:Theme"> 
     <item name="android:windowBackground">@drawable/app_background</item> 
     <item name="android:listViewStyle">@style/TransparentListView</item> 
     <item name="android:expandableListViewStyle">@style/TransparentExpandableListView</item> 
    </style> 

<style name="TransparentListView" parent="@android:style/Widget.ListView"> 
    <item name="android:cacheColorHint">@android:color/transparent</item> 
</style> 

<style name="TransparentExpandableListView" parent="@android:style/Widget.ExpandableListView"> 
    <item name="android:cacheColorHint">@android:color/transparent</item> 
</style> 

</resources> 

的AndroidManifest.xml:

<application android:theme="@style/app_theme">