Android 如何使用ClipDrawable以编程方式显示位图的一部分?
我试图展示图像的某一部分 例如:Android 如何使用ClipDrawable以编程方式显示位图的一部分?,android,image,bitmap,Android,Image,Bitmap,我试图展示图像的某一部分 例如: 我尝试使用下面的代码从位图中设置图像视图的ClipDrawable,但它没有显示 BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap); ClipDrawable clipDrawable = new ClipDrawable(bitmapDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); clipDrawable.s
我尝试使用下面的代码从
位图中设置图像视图的ClipDrawable
,但它没有显示
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
ClipDrawable clipDrawable = new ClipDrawable(bitmapDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
clipDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
clipDrawable.setLevel(5000);
imageView.setImageDrawable(clipDrawable);
我还通过查看imageView.setImageDrawable(BitmapDrawable)
是否会显示完整图像来测试BitmapDrawable
是否存在问题
如何使用ClipDrawable
显示位图的一小部分
为什么图像没有出现
我看了一下,但接受的答案是假设可以从资源中检索图像,而我正在动态加载图像
这篇文章的答案不是用ClipDrawable
回答我的问题,而是用幻数创建一个新的位图
只有在XML中设置了可绘制的
时,才能解释如何解决此问题 设置级别后,您需要在clipdrawable上调用invalidateSelf
,或者您应该尝试以下操作:
imageView.setBackground(clipDrawable);
imageView.setImageResource(android.R.color.transparent);
提供人:设置级别后,您需要在clipdrawable上调用invalidateSelf
,或者您应该尝试以下操作:
imageView.setBackground(clipDrawable);
imageView.setImageResource(android.R.color.transparent);
提供人:设置级别后,您需要在clipdrawable上调用invalidateSelf
,或者您应该尝试以下操作:
imageView.setBackground(clipDrawable);
imageView.setImageResource(android.R.color.transparent);
提供人:设置级别后,您需要在clipdrawable上调用invalidateSelf
,或者您应该尝试以下操作:
imageView.setBackground(clipDrawable);
imageView.setImageResource(android.R.color.transparent);
提供人:您能否只修改setBounds
的width
和height
参数?我不是一个android开发人员,但是看到你如何将它传递到ClipDrawable
,它有一个setBounds
方法,我会这么认为。在第二次阅读您的帖子后,您是否在显示图像时遇到问题?如果是这样的话,你应该让你的帖子与problem@VinceEmigh是的,当我调用imageView.setImageDrawable(clipDrawable)
时,它没有显示。我会编辑这篇文章。您认为我应该如何更改setBounds
方法的参数?检查我的答案:您不能只修改setBounds
的宽度和高度
参数吗?我不是一个android开发人员,但是看到你如何将它传递到ClipDrawable
,它有一个setBounds
方法,我会这么认为。在第二次阅读您的帖子后,您是否在显示图像时遇到问题?如果是这样的话,你应该让你的帖子与problem@VinceEmigh是的,当我调用imageView.setImageDrawable(clipDrawable)
时,它没有显示。我会编辑这篇文章。您认为我应该如何更改setBounds
方法的参数?检查我的答案:您不能只修改setBounds
的宽度和高度
参数吗?我不是一个android开发人员,但是看到你如何将它传递到ClipDrawable
,它有一个setBounds
方法,我会这么认为。在第二次阅读您的帖子后,您是否在显示图像时遇到问题?如果是这样的话,你应该让你的帖子与problem@VinceEmigh是的,当我调用imageView.setImageDrawable(clipDrawable)
时,它没有显示。我会编辑这篇文章。您认为我应该如何更改setBounds
方法的参数?检查我的答案:您不能只修改setBounds
的宽度和高度
参数吗?我不是一个android开发人员,但是看到你如何将它传递到ClipDrawable
,它有一个setBounds
方法,我会这么认为。在第二次阅读您的帖子后,您是否在显示图像时遇到问题?如果是这样的话,你应该让你的帖子与problem@VinceEmigh是的,当我调用imageView.setImageDrawable(clipDrawable)
时,它没有显示。我会编辑这篇文章。您认为我应该如何更改setBounds
方法的参数?请检查我的答案: