【问题标题】:Why is the content of the ImageView empty on my real phone?为什么我的真机上ImageView的内容是空的?
【发布时间】:2016-11-26 14:39:20
【问题描述】:

我尝试将可绘制对象设置为 ImageView。来源取决于月份中的两位数 day-num(存储在 today 中)。我的 API 级别是 17(Fairphone 1)。

在虚拟设备上我可以看到图片。但是当我在我的真实手机上安装应用程序时,ImageBox 在那里但为空(白色)。

这是我设置图像的代码:

ImageView image = (ImageView) findViewById(R.id.startImg);
String uri = "s_"+Integer.parseInt(today);
int imageResource = getBaseContext().getResources().getIdentifier(uri, "drawable", getPackageName());
image.setImageResource(imageResource);

这是我的布局文件:

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:textColor="@color/colorAccent"
        android:textSize="20dp"
        android:paddingBottom="16dp"
        android:id="@+id/textView"
        android:textAlignment="center"
        android:textStyle="bold"
        android:typeface="serif" />
    <ImageView
        android:contentDescription="Bild"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:id="@+id/startImg" />
    <GridView
        android:id="@+id/DatesGrid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="3"
        >
    </GridView>
</LinearLayout>

LogCat 什么也没说。

但我在 API 级别 22(Fairphone 2)上检查了手机上的应用程序。现在应用程序由于错误的imageResource 而崩溃。

问题:为什么我可以在虚拟设备中看到图片,但在真实设备上看不到?

【问题讨论】:

  • logcat 在说什么?
  • 我在我的问题中添加了您要求的信息和更多信息。
  • 我不确定请尝试这个答案stackoverflow.com/a/11737758/3790150
  • String uri = "s_"+Integer.parseInt(today);。那么uri 的值会变成什么?你为什么不告诉?我们怎么知道?

标签: android android-layout android-imageview


【解决方案1】:

感谢大家的提示。我现在可以解决问题了。

存在只能在不同的 API 级别 (22) 上调试的存储分配错误。 17级没有给出任何错误。我现在缩小了图像。这也解释了为什么它可以在具有不同存储设置的虚拟设备上工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-31
    • 1970-01-01
    • 2023-01-05
    • 1970-01-01
    • 2011-08-06
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    相关资源
    最近更新 更多