如何在自定义视图的背景中设置图像

问题描述 投票:-1回答:1

如何将图像从uri设置为自定义视图的背景而不会导致stackoverflow错误。由于我找不到合适的答案,我希望能在这里找到答案。

android view android-custom-view
1个回答
0
投票
  1. 通过Picasso / Glide库获取该图像作为位图
  2. 将位图转换为可绘制的 Drawable drawable = new BitmapDrawable(getResources(), bitmap);
  3. 将drawable设置为自定义视图 yourCustomView.setBackground(drawable);
© www.soinside.com 2019 - 2024. All rights reserved.