With an image saved at res/drawable/myimage.pngXML:<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/myimage" />code:Resources res = getResources(); Drawable drawable = res.getDrawable(R.drawable.myimage);但是要放在工程的res目录下
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/myimage" />code:Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.myimage);但是要放在工程的res目录下
手机软件需要的资源都必须在手机的系统里...不可能手机的软件运行的过程中需要问PC机的本地磁盘去要资源,这根本不可能啊...使用之前要把资源放进res里,或者放在SD卡里
Bitmap bit = BitmapFactory.decodeFile("路径");
Drawable drawable = new BitmapDrawable(bit);
rb.setCompoundDrawablesWithIntrinsicBounds(null, drawable,
null, null);
这样就可以使用本地SD卡中的图片资源了。