欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android設(shè)置重復(fù)文字水印背景的方法

 更新時(shí)間:2022年06月29日 14:51:27   作者:小北的博客  
這篇文章主要為大家詳細(xì)介紹了Android設(shè)置重復(fù)文字水印背景的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android設(shè)置重復(fù)文字水印背景的具體代碼,供大家參考,具體內(nèi)容如下

效果如圖:

自定義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;
? ? }
}

代碼中的設(shè)置:

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"));
? ? }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論