gpt4 book ai didi

android - 为什么这个 ImageView 没有显示我的图像?

转载 作者:行者123 更新时间:2023-11-29 22:29:16 25 4
gpt4 key购买 nike

我的布局上有这个 imageview:

<ImageView
android:id="@+id/profileImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/profileImageLabel"
android:layout_alignParentRight="true"
android:maxWidth="90px"
android:maxHeight="90px"/>

我在 onCreate() 上动态地给它提供图像源:

Bitmap bm = BitmapFactory.decodeFile("c:/logo.png");

profileImage.setImageBitmap(bm);
profileImage.invalidate();

但是当我测试我的应用时,它不显示图像,只显示黑屏。

为什么 imageview 不显示而只是黑屏?

最佳答案

好吧,我觉得你的文件路径是错误的。您正在模拟器中测试它吗?模拟器无法访问您的硬盘驱动器或不属于模拟器的任何其他内容。你应该做的是将你的图像添加到 eclipse 中的可绘制文件夹中(如果你正在使用它),然后通过写入加载文件:

Resources r = this.getResources();
Bitmap bm = BitmapFactory.decodeResource(r, R.drawable.logo);

关于android - 为什么这个 ImageView 没有显示我的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4836441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com