最近开发App,美工设计了一个有锯齿边沿效果的背景图,只给了我一个锯齿,然后需要平铺展示锯齿效果: Android中实现平铺图片有两种方式: (1)在drawable中的
最近开发App,美工设计了一个有锯齿边沿效果的背景图,只给了我一个锯齿,然后需要平铺展示锯齿效果:
Android中实现平铺图片有两种方式:
(1)在drawable中的drawable文件中定义平铺的Bitmap
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="Http://schemas.android.com/apk/res/android"
android:src="@mipmap/ic_border_cupons_left"
android:tileMode="repeat"
>
</bitmap>
(2)在代码中设置
private void initViewBg(ViewHolder holder) {
// 设置内容区域平铺的小圆角背景
Bitmap topBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_border_cupons_left);
BitmapDrawable leftDrawable = new BitmapDrawable(mContext.getResources(), topBitmap);
leftDrawable.setTileModeY(Shader.TileMode.REPEAT);
Bitmap bottomBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_border_cupons);
BitmapDrawable rightDrawable = new BitmapDrawable(mContext.getResources(), bottomBitmap);
rightDrawable.setTileModeY(Shader.TileMode.REPEAT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.favourItemBgLeft.setBackground(leftDrawable);
holder.favourItemBgRight.setBackground(rightDrawable);
} else {
holder.favourItemBgLeft.setBackgroundDrawable(leftDrawable);
holder.favourItemBgRight.setBackgroundDrawable(rightDrawable);
}
}
其中第一种在xml文件中设置部分机型可能出现适配问题,所以这里推荐使用代码方式实现对图片的平铺效果。
您可能感兴趣的文章:android中图片翻页效果简单的实现方法Android实现图片轮播效果的两种方法Android图片特效:黑白特效、圆角效果、高斯模糊Android仿微信发朋友圈浏览图片效果Android仿微信图片点击全屏效果Android实现图片叠加效果的两种方法Android实现图片阴影效果的方法Android模糊处理实现图片毛玻璃效果android实现图片闪烁动画效果的两种实现方式(实用性高)Android编程单击图片实现切换效果的方法Android 轻松实现图片倒影效果实例代码Android编程实现图片平铺的方法分析
--结束END--
本文标题: Android实现平铺图片效果
本文链接: https://www.lsjlt.com/news/25643.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0