【发布时间】:2016-05-18 02:33:07
【问题描述】:
我试图设置一个位图来显示类似的图像:
android:src="img"
但仅来自代码,我从服务器获取 img。 但是当我在做 setImageBitmap() 方法时 它像在背景中一样显示它,就像我会这样做:
android:background="img"
所以无论图像视图中的图像不是黑色,我不想要黑色背景,这是我得到的坏图像: Bad Image
我想得到的图像是: Good Image
如何将代码中位图的图像设置为 xml 中的 src? 太棒了!
这是我的 xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:id="@+id/profile_image"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
app:civ_border_width="5dp"
app:civ_border_color="#c5eaf8"
android:elevation="10dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:layout_centerInParent="true"/>
<ProgressBar
android:id="@+id/progress_bar_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:visibility="gone"/>
</RelativeLayout>
我的位图适用于所有图像,除了像这样的图像,它用黑色填充背景..
【问题讨论】:
-
请提供minimal reproducible example。很可能,您的问题在于如何创建与
setImageBitmap()一起使用的位图。您似乎正在丢失 Alpha 通道。如果我们能看到您的代码,我们只能提供帮助。
标签: java android image background