cod*_*gB2 12 android android-layout android-imageview
目前正在从drawable资源加载图像 -
<ImageView
android:id="@+id/stestImg"
android:src="@drawable/testImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
Run Code Online (Sandbox Code Playgroud)
我可以在这里使用资源中的图像,直接使用布局XML吗?我需要为此做任何编码!请帮忙.
Nik*_*tel 21
你可以这样做::
ImageView i;
Bitmap bm = getBitmapFromAsset("pic1.png");
i = (ImageView)findViewById(R.id.image);
i.setImageBitmap(bm);
Run Code Online (Sandbox Code Playgroud)
通话方法::
private Bitmap getBitmapFromAsset(String strName) throws IOException
{
AssetManager assetManager = getAssets();
InputStream istr = assetManager.open(strName);
Bitmap bitmap = BitmapFactory.decodeStream(istr);
return bitmap;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9359 次 |
最近记录: |