vir*_*sir 312 layout android image
我在我的应用程序中设置了背景图像,但背景图像很小,我想重复它并填写整个屏幕.我该怎么办?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg"
android:tileMode="repeat">
Run Code Online (Sandbox Code Playgroud)
yan*_*nko 423
好的,这就是我在我的应用程序中得到的内容.它包括一个黑客,以防止ListView滚动时黑色.
drawable/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" />
Run Code Online (Sandbox Code Playgroud)
values/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>
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml:
//
<application android:theme="@style/app_theme">
//
Run Code Online (Sandbox Code Playgroud)
Las*_*osi 170
可绘制的xml中有一个属性可以执行此操作.机器人:TILEMODE = "回头客"
查看此站点:http: //androidforbeginners.blogspot.com/2010/06/how-to-tile-background-image-in-android.html
plo*_*man 67
这是一个重复的背景图像的纯java实现:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.bg_image);
BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
LinearLayout layout = new LinearLayout(this);
layout.setBackgroundDrawable(bitmapDrawable);
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我们的背景图像必须存储在res/drawable/bg_image.png中.
小智 14
扩展了plowman的答案,这里是使用java更改背景图像的非弃用版本.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.texture);
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),bmp);
bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT,
Shader.TileMode.REPEAT);
setBackground(bitmapDrawable);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
201540 次 |
| 最近记录: |