Android ImageView在模拟器上显示,但不在设备上显示 [英] Android ImageView Displays on Emulator but not on Device

查看:154
本文介绍了Android ImageView在模拟器上显示,但不在设备上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在AndroidStudio中尝试将图像设置为由相机拍摄后显示在屏幕上.这在模拟器上可以正常工作,但是当我在设备(Nexus 5)上对其进行测试时,图像没有显示出来.

I am working in AndroidStudio trying to set an image to display on the screen after it is taken by the camera. This is working flawlessly on the emulator but when I test it on my device (Nexus 5) the image does not show up.

我尝试缩小无法使用的图像,还尝试在我的drawables文件夹中使用一个小图像,以确保它不是文件路径问题(可绘制图像也显示在模拟器上,而不显示在我的手机).我还尝试将位图转换为可绘制的图像并将其设置为imageView的背景,这也无法正常工作.我不确定目前还有什么尝试.

I have tried scaling down my image which didn't work, I also tried using a small image in my drawables folder to make sure it wasn't a file path issue (the drawable image also displayed on the emulator but not on my phone). I also tried converting the bitmap to a drawable and setting it to the background of the imageView which also didn't work. I am not sure what else to try at this point.

我应该补充一点,如果我将图像以XML的形式显式添加为背景,它将显示在我的设备上,这使我认为它是我的java.另一方面,我可以使用相同的Java代码将图像显示在另一个活动中,这使我认为它是布局.

I should add that if I explicitly add the image in the XML as a background it will show up on my device which makes me think it is my java. On the other hand I can get the image to show up on another activity with this same java code which makes me think it is the layout.

File file = cameraShot;
ImageView leftEye = (ImageView) view.findViewById(R.id.ghostAlign);
if(leftEye != null) {
  Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath());
  leftEye.setImageBitmap(bmp);
}

布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/cameraFrag"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:foreground="?selectableItemBackground"
    android:tag="ScopiCamera"
    tools:ignore="UnusedAttribute">


    <FitTextureView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/texture"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true" />

    <ImageView
        android:id="@+id/ghostAlign"
        android:scaleType="fitXY"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="false"
        android:alpha="0.5" />
</FrameLayout>

推荐答案

我建议您查看是否没有由于加载图像而导致的内存问题.请参阅来自文档的此页面,以减少以下情况下的内存消耗:加载图片.

I'd suggest you to see if there is no memory problem due to loading your image. See this page from doc in order to reduce memory consumption when loading your image.

我也遇到了这个问题,图像是在其他设备上打开的,但在我的手机上没有打开.也许通过正确加载位图,它会起作用.

I had this problem too, the image was opened on other devices but not on my phone. Maybe by properly loading your bitmap, it will works.

这篇关于Android ImageView在模拟器上显示,但不在设备上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆