3

我正在为 Android 开发一个应用程序,我正在使用 Gallery 小部件,并且我已将其调整为全屏模式,因此它一次显示一个图像。

<com.example.librosapp.MyGallery 
        android:id="@+id/examplegallery" android:layout_width="1920px"
        android:layout_height="1020px"
        android:padding="0px"
        android:layout_marginTop="-20px"
        />

这是我的活动代码的一部分:

public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imgView = new ImageView(cont);

        //Here are my changes:
        File imgFile = new  File("sdcard/Libreria/0/0/0.JPG");
        if(imgFile.exists()){
            Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
            //The app runs OK til here:
            imgView.setImageBitmap(myBitmap);
            //BOOM! Exception
        }           

        imgView.setLayoutParams(new MyGallery.LayoutParams(1950, 1000));
        imgView.setScaleType(ImageView.ScaleType.FIT_XY);


        return imgView;
    }

我不知道我得到了哪个异常,因为我无法在这里调试,我在我的设备中使用 .APK。(我必须调试这个的唯一方法是使用虚拟设备,我不知道为什么它运行得非常慢。

我做错了吗?,如果我使用相同的图像,该代码可以完美运行,但作为项目资源(使用 setImageDrawable)

4

1 回答 1

1

发生这种情况是因为myBitMap为空。 myBitMap为空,因为文件路径无效。我的猜测是文件路径应该是/sdcard/Libreria/0/0/0.JPG

于 2013-11-19T22:47:48.277 回答