我使用ImageView从sdcard显示图像时遇到问题。我尝试了很多代码,下面是这些代码,但没有人为我工作,知道该活动运行时没有任何问题“成功”,但屏幕始终为空,并且不显示图像。任何想法。提前致谢。ImageView不显示来自特定文件夹的图像
activity_mainvie.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".IMAGEVIE" >
<ImageView
android:id="@+id/imageview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"/>
</RelativeLayout>
代码试图的主要活动是:
public class IMAGEVIE extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_imagevie);
ImageView iv=(ImageView) findViewById(R.id.imageview);
Bitmap bMap = BitmapFactory.decodeFile("/sdcard/life.jpg");
iv.setImageBitmap(bMap);
}
}
第二个代码:
public class IMAGEVIE extends Activity {
private File mFichier;
private Uri fileUri;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_imagevie);
ImageView iv=(ImageView) findViewById(R.id.imageview);
File f= new File("/sdcard/life.jpg");
Bitmap bMap = BitmapFactory.decodeFile(f.getAbsolutePath());
iv.setImageBitmap(bMap);
}
}
第三代码:
public class IMAGEVIE extends Activity {
private File mFichier;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_imagevie);
ImageView iv=(ImageView) findViewById(R.id.imageview);
mFichier = new File(Environment.getExternalStorageDirectory(),"life.jpg");
if(mFichier.exists())
{
iv.setImageURI(Uri.fromFile(mFichier));
}
}
}
该文件是否存在? – Blackbelt
是的,它是存在的。当我使用GridView时,我遇到了同样的问题。总是一个空的屏幕没有错误。 – sinimm