내 res/drawable 폴더에서 이미지를로드하려고합니다. Android 개발자 Link에서 가이드를 사용했습니다. 내가 얻는 유일한 오류는 "SPAN_EXCLUSIVE_EXCLUSIVE 스팬 길이가 0 일 수 없다"는 어떤 이유로 든 작동하지 않습니다. 제가 조사한 사실은 맞춤 키보드와 관련이 있습니다.하지만 텍스트 입력을 전혀 사용하지 않고 있습니다. 앱 자체 당신이 나를 도울 수 있기를 바랍니다 :) 레이아웃 파일에는 ImageView가있는 RelativeLayout이 포함되어 있습니다.ImageView에서 이미지를로드 할 수 없습니다. (jpg, png, ...)
public class PixelActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pixel);
String uri = "@drawable-hdpi/testbild.png";
final int imageResource = getResources().getIdentifier(uri, null, getPackageName());
final ImageView iv = (ImageView) findViewById(R.id.imageview1);
//int imageHeight = options.outHeight;
//int imageWidth = options.outWidth;
//String imageType = options.outMimeType;
new Thread(new Runnable()
{
public void run()
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), imageResource, options);
iv.post(new Runnable()
{
public void run()
{
iv.setImageBitmap(decodeSampledBitmapFromResources(getResources(),imageResource,iv.getWidth(),iv.getHeight()));
//iv.setImageResource(R.drawable.testbild);
}
});
}
});
}
public static int calculateInSampleSize(BitmapFactory.Options options,int reqWidth, int reqHeight)
{
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if(height > reqHeight || width > reqWidth)
{
final int heightRatio = Math.round((float)height/(float)reqHeight);
final int widthRatio = Math.round((float)width/(float)reqWidth);
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
return inSampleSize;
}
public static Bitmap decodeSampledBitmapFromResources(Resources res, int resId, int reqWidth, int reqHeight)
{
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
options.inSampleSize = calculateInSampleSize(options,reqWidth,reqHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
} 무효
대신 view.post의 runOnUiThread를 사용해보십시오. View.post는 때때로 전혀 호출되지 않습니다. Handler.post 및 Activity.runOnUiThread만이 항상 나를 위해 일합니다. –