4

Android Universal Image loaderを使用しているギャラリーがあります。問題は、画像の半分のように、画像が部分的にしか表示されないことです。画像がまったく表示されないこともありますが、画像全体が表示されることもあります。

DisplayImageOptions options = new DisplayImageOptions.Builder()
                                            .cacheInMemory()
                                            .build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                                            .defaultDisplayImageOptions(options)
                                            .threadPoolSize(1)
                                            .threadPriority(Thread.MIN_PRIORITY + 3)
                                            .denyCacheImageMultipleSizesInMemory()
                                            .memoryCacheSize(2 * 1024 * 1024)
                                            .enableLogging()
                                            .build();

imageLoader = ImageLoader.getInstance();
imageLoader.init(config); 
imageLoader.handleSlowNetwork(true);


subImage1 = (ImageView)findViewById(R.id.subImage1);
subImage2 = (ImageView)findViewById(R.id.subImage2);

imageLoader.displayImage( "http://path/to/image1.webp", subImage1);
imageLoader.displayImage( "http://path/to/image2.webp", subImage2);

レイアウト

<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"
   android:paddingBottom="@dimen/activity_vertical_margin"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   tools:context=".MyActivity" >



<ImageView
    android:id="@+id/subImage1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true" />

<ImageView
    android:id="@+id/subImage2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignTop="@+id/subImage1"/>


</RelativeLayout>

問題の例

ここに画像の説明を入力

何が問題なのですか?

4

2 に答える 2

1

私は同じ問題を抱えていました

あなたが探している解決策は、ここにあると思います

//Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE=70;
int width_tmp=o.outWidth, height_tmp=o.outHeight;
int scale=1;
while(true){
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
    break;
width_tmp/=2;
height_tmp/=2;
scale*=2;
}

これは、99 行目から 108 行目までです: https://github.com/thest1/LazyList/blob/master/src/com/fedorvlasov/lazylist/ImageLoader.java

ソースからコードを確認し、コードと比較できるように、これをリンクしています。

ここでこのビットを変更する必要があります: final int REQUIRED_SIZE=70. この数値は 2 のべき乗であることに注意してください。デフォルトの 70 では、小さな画像が表示され、大きな画像を表示する必要があるアプリケーションで使用すると、画像がゆがんで見えます。結果に満足するまで、それで遊んでください。

私は個人的に final int REQUIRED_SIZE=512 の値を問題なく使用しています。

これでうまくいくはずです。

于 2013-04-30T09:03:17.023 に答える
1

最後に、いくつかのテストを行った結果、Android v4.0 の ImageView は webp を正しく表示できないという結論に達しました。私が見つけた唯一の解決策は、webView で webp 画像を表示することです。これにより、このファイル タイプが適切にレンダリングされます

于 2013-04-30T15:49:47.557 に答える