无名商城论坛

搜索
查看: 242|回复: 0

[其他技术] 【菜鸟】设置线性布局背景为QQ气泡

[复制链接]

1万

主题

1万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
32464
发表于 2022-5-8 17:59:24 | 显示全部楼层 |阅读模式
mjava 代码 :

import android.graphics.*;
    import android.graphics.drawable.*;
    setNine(android.widget.LinearLayout view, String path){
        Bitmap bitmap= BitmapFactory.decodeFile(path);
        NinePatchDrawable nineDrawable= null;
         byte[] chunk = bitmap.getNinePatchChunk();  // 如果.9.png没有经过第一步,那么chunk就是null
         if(NinePatch.isNinePatchChunk(chunk)) {
             NinePatchDrawable patchy = new NinePatchDrawable(bitmap, chunk, new Rect(), null);
            view.setBackground(patchy);
         }
    }

调用方法:

    gvs(st_vW, Card.8, bubble)
    s path = "/storage/emulated/0/1/images/skin_aio_friend_bubble_nor.9.png"
    call(null, "mjava", "ui.setNine", bubble, path)
    // 注意:Card.8 是线性布局控件
    // path 必须是绝对路径。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表