0

showでグリッドビューitemを表示する方法、アプリケーションでGridViewframeを使用していますが、今ではすべてを表示する必要がありますgrid itemframe

私はblack色を として使用しており、いくつか(白など)backgroundを使用したいので、どのようにグリッドアイテムのフレームとして使用できますか?frameother colorwhite

    <ImageView
        android:id="@+id/imageItem"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:background="@null"
        android:contentDescription="@null"
        />
4

2 に答える 2

3

フレーム内に画像を表示するには、2 つの方法があります。

  1. 背景画像または色を設定して、画像がフレーム内にあることを示します
  2. マスキングの設定

BackGround を設定する場合:

<ImageView
    android:id = "@+id/imageItem"
    android:layout_width = "match_parent"
    android:layout_height = "wrap_content"
    android:adjustViewBounds = "true"
    android:scaleType = "center"
    android:padding = "5dp"
    android:background = "#FFFFFF"
    android:contentDescription = "@null" />

マスキングについては、次のコードを確認してください。

ImageView mImageView= (ImageView)findViewById(R.id.imageview_id);
Bitmap original = BitmapFactory.decodeResource(getResources(),R.drawable.content_image);
Bitmap mask = BitmapFactory.decodeResource(getResources(),R.drawable.mask);
Bitmap result = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Config.ARGB_8888);
Canvas mCanvas = new Canvas(result);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
mCanvas.drawBitmap(original, 0, 0, null);
mCanvas.drawBitmap(mask, 0, 0, paint);
paint.setXfermode(null);
mImageView.setImageBitmap(result);
mImageView.setScaleType(ScaleType.CENTER);
mImageView.setBackgroundResource(R.drawable.background_frame);

背景として色を表示したい場合は、最初のオプションの方がはるかに優れており、効率的です。

于 2014-10-14T05:38:18.270 に答える
0

次のコードを使用して、フォルダーにXMLファイルを保存します。Drawable

<?xml version="1.0" encoding="utf-8"?>

<item android:state_enabled="true"><shape>
        <solid android:color="#FFFFFF" />

        <stroke android:width="1dp" android:color="#CACACA" />

        <corners android:radius="5dp" />

 <!--       <padding android:bottom="5dp" android:left="5dp" android:right="5dp" android:top="5dp" />-->
    </shape></item>

これを画像ビューの背景として使用し、画像を背景リソースとして設定します。 ソース

<ImageView
        android:id="@+id/imageItem"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:background="@drawable/your_xml_name"
        android:contentDescription="@null"
        />
于 2014-10-14T05:28:47.160 に答える