《=用来反复显示的图
1.最简单方式
创建wave_repeat.xml
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
< bitmap xmlns:android = "http://schemas.android.com/apk/res/android"
android:src = "@drawable/wave"
android:tileMode = "repeat" />
< bitmap xmlns:android = "http://schemas.android.com/apk/res/android"
android:src = "@drawable/wave"
android:tileMode = "repeat" />
在layout中使用
<
View
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:background = "@drawable/wave_repeat" />
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:background = "@drawable/wave_repeat" />
这样的方式有一个问题。最后一张
反复
图片不一定是完整的图片可能仅仅是一部分
效果图:(左右两条竖线是后来加的)
2.可确保最后一张反复图片是完整的。就是几个完整的一样的图片X轴反复
Resources res =
context
.getResources();
Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable. wave );
holder. viewWave .setImageBitmap(BitmapHelper.createRepeater( screenWidth , bitmap)); //screenWidth为屏幕宽度(或显示图片的 imageview 宽度)
Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable. wave );
holder. viewWave .setImageBitmap(BitmapHelper.createRepeater( screenWidth , bitmap)); //screenWidth为屏幕宽度(或显示图片的 imageview 宽度)
BitmapHelper.java 中的方法
public
static
Bitmap createRepeater(
int
width, Bitmap src) {
int count = (width + src.getWidth() - 1) / src.getWidth(); //计算出平铺填满所给width(宽度)最少须要的反复次数
Bitmap bitmap = Bitmap.createBitmap(src.getWidth()*count, src.getHeight(), Config. ARGB_8888 );
Canvas canvas = new Canvas(bitmap);
for ( int idx = 0; idx < count; ++idx) {
canvas.drawBitmap(src, idx * src.getWidth(), 0, null );
}
return bitmap;
}
int count = (width + src.getWidth() - 1) / src.getWidth(); //计算出平铺填满所给width(宽度)最少须要的反复次数
Bitmap bitmap = Bitmap.createBitmap(src.getWidth()*count, src.getHeight(), Config. ARGB_8888 );
Canvas canvas = new Canvas(bitmap);
for ( int idx = 0; idx < count; ++idx) {
canvas.drawBitmap(src, idx * src.getWidth(), 0, null );
}
return bitmap;
}
在layout中设置imageview的scaleType为fitXY
<
ImageView
android:id = "@+id/view_wave"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:scaleType = "fitXY" />
android:id = "@+id/view_wave"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:scaleType = "fitXY" />
效果图:
本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5087711.html,如需转载请自行联系原作者