【发布时间】:2016-02-19 19:05:18
【问题描述】:
我想知道 Pocket Casts 应用程序是如何创建其导航栏背景图像的。据我所知,他们从您订阅的播客中获取图像,并以某种方式创建此图像并将其设置为导航栏背景。很酷的效果!
在重新创建类似的东西方面有什么技巧吗?
谢谢!
【问题讨论】:
标签: android uinavigationbar material-design android-image
我想知道 Pocket Casts 应用程序是如何创建其导航栏背景图像的。据我所知,他们从您订阅的播客中获取图像,并以某种方式创建此图像并将其设置为导航栏背景。很酷的效果!
在重新创建类似的东西方面有什么技巧吗?
谢谢!
【问题讨论】:
标签: android uinavigationbar material-design android-image
NavigationView 的标题的宽度和高度创建一个空的Bitmap。 Bitmap 图像,并在Canvas 上将它们按比例绘制。您总是从0 绘制到scaledBitmap.getWidth(),然后scaledBitmap.getWidth() 应该被保存为下一个Bitmap 的下一个起点。对高度执行相同的逻辑。出于内存和性能原因,将您要绘制的Bitmap 的数量限制在一定数量。 ImageView 中的Matrix 作为标题视图的一部分并将其旋转一定角度ColorFilter 应用于整个标题视图。这也可以通过旋转drawable来完成。
【讨论】:
按照@Nikola 回答的步骤:
public static Bitmap createBitmap(int width, int height, List<Bitmap> bitmaps) {
final Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(newBitmap);
final Paint paint = new Paint();
paint.setAlpha(50);
int currentWidth = 0;
int currentHeight = 0;
for (Bitmap scaledBitmap : bitmaps) {
//draw the bitmap
canvas.drawBitmap(scaledBitmap, currentWidth, currentHeight, paint);
//update width
currentWidth += scaledBitmap.getWidth();
//update height
if (currentWidth > width) {
currentWidth = 0;
currentHeight += scaledBitmap.getHeight();
}
}
return newBitmap;
}
主要区别在于我最终设置了透明度(使用 setAlpha)而不是 ColorFilter。
如果最后您仍想旋转,只需在将保存您的位图的图像视图中调用 imageView.setRotation(degree)。
干杯
【讨论】: