2016-04-27 20 views
0

私は左の画像でカスタムListViewを使用するAndroidプロジェクトに取り組んでいます。
Genemotionエミュレータを使用していますが、問題なく動作します。画像が完全に示されている:私は私のデバイス(Huawei社P8ライト)でアプリを使用する場合 Screenshot from Genymotion emulator画像はエミュレータで表示されますが、実際のデバイスでは表示されません

しかし、何も表示されません:Screenshot from device

が、私は私のデバイス上でアプリケーションをデバッグしようとした、画像パス存在している(そうでない場合は代わりに「利用可能なイメージはありません」そのないだろう)ANSです:/storage/emulated/0/Pictures/JPEG_20160415_134349_-350854394.jpg
私は、Androidデバイスモニタに行って、画像が存在するが、少し違うパス(mnt/shell /の代わりに/ storage /でも、これは本当の問題だとは思わないでしょうか?)
スタックトレースに「OutOfMemory」エラーやその他のエラーはありません。
これは私が絵を表示するために使用するコードです:

if(values.get(position).getImgList().size()==0){ 
     imageView.setImageResource(R.drawable.nopics); 
    } 
    else { 
    //getImg() return the path (string) of the first image in a ArrayList of path 
     imageView.setImageBitmap(values.get(position).getImg()); 
    } 

私はWebサービスへのイメージを送信するとき、私は同じメソッドを使用してgetImgは()画像を返すことをかなり確信しています。 Webサービスが画像を正しく受信します。
私はAndroidマニフェストに内部/外部ストレージを読み書きしています。

EDIT:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="horizontal"> 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
<ImageView 
    android:id="@+id/icon" 
    android:layout_width="200px" 
    android:layout_height="200px" 
    android:layout_marginLeft="40px" 
    android:layout_marginRight="10px" 
    android:layout_marginTop="4px"> 
</ImageView> 
</RelativeLayout> 
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
<TextView 
    android:id="@+id/label" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="70px" 
    android:layout_marginLeft="10px" 
    android:text="@+id/label" 
    android:layout_marginRight="@dimen/activity_horizontal_margin" 
    android:textSize="48px" > 
</TextView> 

<ImageButton 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:id="@+id/croixrouge" 
    android:src="@drawable/croixrouge" 
    android:layout_alignBottom="@+id/label" 
    android:layout_marginBottom="50px" 
    android:layout_alignEnd="@+id/label" /> 

    <ImageButton 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:id="@+id/option" 
     android:src="@drawable/modif" 
     android:layout_alignTop="@+id/croixrouge" 
     android:layout_toStartOf="@+id/croixrouge" 
     android:layout_marginRight="5px"/> 

    <ImageButton 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:id="@+id/refresh" 
     android:src="@drawable/refreshpurple" 
     android:layout_alignTop="@+id/option" 
     android:layout_toStartOf="@+id/option" 
     android:layout_marginRight="5px" /> 
</RelativeLayout> 
<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10px" 
    android:id="@+id/sublabel" 
    android:text="@+id/sublabel" 
    android:layout_marginRight="@dimen/activity_horizontal_margin" 
    android:textSize="32px"/> 

</LinearLayout> 

</LinearLayout> 

getImg()コード:

public Bitmap getImg() { 
    if(imgList.size() !=0) { 
     Bitmap bmp = BitmapFactory.decodeFile(imgList.get(0)); 
     return bmp; 
    } 
    return null; 
} 

編集:私は、画像を選ぶ方法:私はレイアウトコードを忘れた 保護のボイドonActivityResult(int型requestCode、int型のresultCodeを、 インテント画像データ){ super.onActivityResult(requestCode、resultCode、imageData);

switch (requestCode) { 
     case Define.ALBUM_REQUEST_CODE: 
      if (resultCode == RESULT_OK) { 
       path = imageData.getStringArrayListExtra(Define.INTENT_PATH); 
... 
      } 
    } 
} 

以降:

r.setImgList(path); 

は、誰かが画像を実際のデバイスに表示されていない理由を私は理解する助けていただけますか?

+0

をありがとう:ImageViewの –

+0

でscaleType =「fitXY」エミュレータやデバイスのAPIレベルは何ですか? – nvi9

+0

scaleTypeはうまくいきませんでしたが、ありがとうございます。エミュレータとデバイスは両方ともAPI 21、デバイスはAndroid 5.0.1で動作し、エミュレータは5.0.0で – Nevi

答えて

0

これは、ImageViewで解像度を上げてイメージをロードしようとすると発生します。複数の解像度とサイズをサポートするには、複数のサイズ(ldpi、mdpi、hdpi、xhdpi、xxhdpi、xxxhdpi)に縮小する必要があります。

あなたはあなたのイメージの実際のパスを取得するには、このヘルパー・メソッドを使用することができ、このlink

0

を参照してください。 getImg()メソッドで、ヘルパーメソッドから作成したパスを渡します。

public Bitmap getImg() { 
    if(imgList.size() != 0) { 
     Uri uri = Uri.parse(imgList.get(0)); 
     String path = getRealPathFromUri(getActivity(), uri) 
     Bitmap bmp = BitmapFactory.decodeFile(path); 
     return bmp; 
    } 
    return null; 
} 

public String getRealPathFromURI(Context context, Uri uri) { 
    String path; 
    if ("content".equals(uri.getScheme())) { 
     path = getRealPathFromContentURI(context, uri); 
    } else if ("file".equals(uri.getScheme())) { 
     path = uri.getPath(); 
    } else { 
     path = uri.toString(); 
    } 
    return path; 
} 

private String getRealPathFromContentURI(Context context, Uri contentUri) { 
    if (contentUri == null) { 
     return null; 
    } 

    String[] proj = { MediaStore.Images.Media.DATA }; 
    CursorLoader loader = new CursorLoader(context, contentUri, proj, null, null, null); 
    Cursor cursor = loader.loadInBackground(); 

    if (cursor == null) { 
     return null; 
    } 

    int column_index = cursor.getColumnIndex(MediaStore.Images.Media.DATA); 
    if (column_index == -1) { 
     cursor.close(); 
     return null; 
    } 

    String path; 
    if (cursor.moveToFirst()) { 
     path = cursor.getString(column_index); 
    } else { 
     path = null; 
    } 

    cursor.close(); 
    return path; 
} 
+0

答えがありがとうございます。それは私の画像をrezise、理由はありません)しかし、私のAndroidデバイスでも同じ問題 – Nevi

+0

値の配列に保存される画像パスを取得する方法 – muazhud

+0

あなたのレイアウトコードは、常にppではなくdp値を使用して、さまざまなアンドロイドデバイスで – muazhud

0

問題を修正しました。
ビットマップを拡大/縮小しました。それは画面や何かに合っていないようです...

public Bitmap getImg() { 
    if(imgList.size() !=0) { 
     Bitmap bmp = BitmapFactory.decodeFile(imgList.get(0)); 
     int nh = (int) (bmp.getHeight() * (800.0/bmp.getWidth())); 
     Bitmap scaled = Bitmap.createScaledBitmap(bmp, 600, nh, true); 
     return scaled; 
    } 
    return null; 
} 

それは多分、このアンドロイドを試してみ合わないあなたの助け

関連する問題