Android设置重复文字水印背景的方法
更新时间:2022年06月29日 14:51:27 作者:小北的博客
这篇文章主要为大家详细介绍了Android设置重复文字水印背景的方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud)
(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun)
本文实例为大家分享了Android设置重复文字水印背景的具体代码,供大家参考,具体内容如下
效果如图:
自定义Drawable :
/** ?* Created by Owen Chan ?* On 2017-07-05. ?*/ public class WaterMarkBg extends Drawable { ? ? private Paint paint = new Paint(); ? ? private String logo = "SoYoung"; ? ? public WaterMarkBg(String logo) { ? ? ? ? this.logo = logo; ? ? } ? ? @Override ? ? public void draw(@NonNull Canvas canvas) { ? ? ? ? int width = getBounds().right; ? ? ? ? int height = getBounds().bottom; ? ? ? ? canvas.drawColor(Color.parseColor("#F3F5F9")); ? ? ? ? paint.setColor(Color.parseColor("#AEAEAE")); ? ? ? ? paint.setAntiAlias(true); ? ? ? ? paint.setTextSize(30); ? ? ? ? canvas.save(); ? ? ? ? canvas.rotate(-30); ? ? ? ? float textWidth = paint.measureText(logo); ? ? ? ? int index = 0; ? ? ? ? for (int positionY = height / 10; positionY <= height; positionY += height / 10) { ? ? ? ? ? ? float fromX = -width + (index++ % 2) * textWidth; ? ? ? ? ? ? for (float positionX = fromX; positionX < width; positionX += textWidth * 2) { ? ? ? ? ? ? ? ? canvas.drawText(logo, positionX, positionY, paint); ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? canvas.restore(); ? ? } ? ? @Override ? ? public void setAlpha(@IntRange(from = 0, to = 255) int alpha) { ? ? } ? ? @Override ? ? public void setColorFilter(@Nullable ColorFilter colorFilter) { ? ? } ? ? @Override ? ? public int getOpacity() { ? ? ? ? return PixelFormat.UNKNOWN; ? ? } }
代码中的设置:
public class MainActivity extends AppCompatActivity { ? ? @Override ? ? protected void onCreate(Bundle savedInstanceState) { ? ? ? ? super.onCreate(savedInstanceState); ? ? ? ? setContentView(R.layout.activity_main); ? ? ? ? findViewById(R.id.text).setBackground(new WaterMarkBg("Owen Chan")); ? ? } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持程序员之家。
相关文章
Android开发实现仿QQ消息SwipeMenuListView滑动删除置顶功能【附源码下载】
这篇文章主要介绍了Android开发实现仿QQ消息SwipeMenuListView滑动删除置顶功能,结合实例形式分析了Android swipemenulistview相关组件的使用技巧,并附带demo源码供读者下载参考,需要的朋友可以参考下2017-12-12Android自定义listview布局实现上拉加载下拉刷新功能
这篇文章主要介绍了Android自定义listview布局实现上拉加载下拉刷新功能,非常不错,具有参考借鉴价值,需要的朋友可以参考下2016-12-12
最新评论