0

画像を表示するための gridView レイアウトがあり、マークされた画像の上に小さなアイコンを配置したいと考えています。

ここに私のコード:

ImageView i;
    if (convertView == null) {  
        i = new ImageView(mContext);
        i.setLayoutParams(new GridView.LayoutParams(width, height));
        i.setPadding(10, 10, 10, 10);
        i.setScaleType(ImageView.ScaleType.CENTER_CROP);

    } else {
        i = (ImageView) convertView;
    }

    if(mImageSet == IMAGE_SET_ONE) { 
            boolean cek = true;
            i.setImageBitmap(decodeSampledBitmapFromResource(mContext.getResources(),mThumbIds[position],width,width)); 

    }

助けてください..

4

2 に答える 2

3

ImageView ウィジェットには、背景と前景の画像を設定する機能が組み込まれています。xml でどのように見えるかを確認できます。src フィールドと background フィールドは、ImageView の setImageResource メソッドと setImageBackground メソッドで設定できます。

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

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_centerInParent="true"
        android:background="@color/pink"
        android:src="@drawable/facebook_icon" />

</RelativeLayout>

最初の例

これに関する唯一の問題は、src (オーバーレイ) 画像が画像ビューの高さまたは幅のいずれかと一致することです。

したがって、これを回避するには、相対で複数の画像ビューを使用し、それぞれに背景または src を個別に設定する必要があります。

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

    <ImageView
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_centerInParent="true"
        android:background="@color/pink" />

        <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_centerInParent="true"
        android:src="@drawable/facebook_icon" />

</RelativeLayout>

2 番目の例

于 2013-07-24T15:08:54.780 に答える