3

私のアプリの画面の1つには、6列のリストビューが表示されます。6番目の画面は、ユーザーが作成した画像またはスケッチを含むimageViewです。listView行のコードは次のとおりです。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingTop="2dp"
    android:paddingBottom="2dp" >

    <TextView android:id="@+id/surveyColumn1"
        android:textSize="13sp"
        android:layout_width="0dip"
        android:layout_weight="0.105"
        android:layout_height="wrap_content"/>

    <TextView android:id="@+id/surveyColumn2"
        android:textSize="13sp"
        android:layout_width="0dip"
        android:layout_weight="0.137"
        android:layout_height="wrap_content"/>

    <TextView android:id="@+id/surveyColumn3"
        android:textSize="12sp"
        android:layout_width="0dip"
        android:layout_weight="0.25"
        android:layout_height="wrap_content"/>

    <TextView android:id="@+id/surveyColumn4"
       android:textSize="13sp"
        android:layout_width="0dip"
        android:layout_weight="0.153"
        android:layout_height="wrap_content"/>

    <TextView android:id="@+id/surveyColumn5"
        android:textSize="13sp"
        android:layout_width="0dip"
        android:layout_weight="0.153"
        android:layout_height="wrap_content"/>

    <ImageView android:id="@+id/surveyColumn6"
        android:layout_width="0dip"
        android:layout_weight="0.202"
        android:layout_height="wrap_content"
        android:paddingTop="0dp"
        android:paddingBottom="0dp"
        android:scaleType="centerInside"
        android:layout_gravity="center"
        android:contentDescription="@string/pictureHeader"/>

</LinearLayout>

この設定は、表示されている画像がカメラによって撮影された垂直方向の画像である場合を除いて、うまく機能します。その場合、リストビューは行内の画像の上下に大量の空白スペースをスローします。アクティビティでは、custumViewBinderを使用して、ここから取得したコードを使用して画像をビットマップとして表示しています:http: //developer.android.com/training/displaying-bitmaps/load-bitmap.html

スペースを取り除くために私が見つけた唯一の方法は、静的な高さをimageViewに設定することです。これは、一部の行に画像がないため、私はむしろ行いません。何が起こっているのかを理解できる人は誰でも私のヒーローです。

編集:画像をビットマップとして表示するために呼び出すクラスは次のとおりです。

public class customBitmap {

    public customBitmap(String pathName, int width, int height, ImageView view) {
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(pathName, options);

        options.inSampleSize = calculateInSampleSize(options, width, height);

        options.inJustDecodeBounds = false;
        Bitmap bitmap = BitmapFactory.decodeFile(pathName, options);

        //Check if bitmap was created; if so, display it in the imageView
        if(bitmap == null)
            Log.w("UI Thread", "Null bitmap at moto.sitesurvey.customBitmap:35");
        else
            view.setImageBitmap(bitmap);
    }

    public 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) {
            if(width > height)
                inSampleSize = Math.round((float)height / (float)reqHeight);
            else
                inSampleSize = Math.round((float)width / (float)reqWidth);
        }

        return inSampleSize;
    }

}

アクティビティでは、幅と高さの値として200と150を渡します。私の問題は、数か月前にこのコードを最初に書いたとき、横向きの写真でのみ機能するように設計し、今ではポートレートでも機能する必要があることです。

4

2 に答える 2

2

r / androiddevの私の投稿でのstoney80の提案に従って、私は次の行を追加しました

android:adjustViewBounds="true"

imageVewに、そしてこれは私が望んでいたことを正確に実行するようになりました。

于 2013-02-07T18:41:52.303 に答える
0

ビューに配置する前に画像のサイズを変更していますか?その場合は、画像が機能する最適なサイズを確認し、垂直方向のカメラから取得したビットマップのサイズをこのサイズに変更してみてください。

これで問題が解決しない場合は、imageviewとビットマップコードを確認できますか?

于 2013-02-04T20:04:39.803 に答える