4

私は2つの画像を持っています - 1)実際のコンテンツを表示する長方形の画像と2)透明な角が丸い白い画像

画像 1 を画像 2 の中に配置し、サイズを維持しながら 2 と同じ形にすることはできますか?

基本的に、画像2を画像1のコンテナにしたい.

レイヤーとインセットのドローアブルを試しましたが、常に画像 1 が画像 2 に重なっています。

前もって感謝します!

更新 1:

ここに私の ImageView xml 部分があります:

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

    <ImageView
        android:id="@+id/avatar"
        android:src="@drawable/mainImg"
        android:background="@drawable/backgroundImg"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:layout_gravity="center"
        android:contentDescription="@string/desc" />

</LinearLayout>

更新 2:

以下は、3 つの画像へのリンクです。1) 背景 2) メイン画像 3) 期待される結果 (角が丸い)

ImageShack のアップロード

4

3 に答える 3

4

最近作成したアプリでこの問題に対処する必要がありました。1番目と2番目のスクリーンショットで、サムネイルがすべてフレーム化されていることに注目してください。

これを実現するために、FrameLayoutで画像とフレームを積み重ねています。最初に実際の画像(@ id / thumbnail)をレイアウトし、次にフレーム(@ id / frame)をレイアウトします。

注意すべき重要な点は、サムネイルが「fitXY」のscaleTypeを使用しており、フレームの丸い角の後ろに角が突き出ないようにわずかなマージンがあることです。

これは実際にはフレームの境界が不透明な場合にのみ機能するため、フレームのエッジを背景と同じ色にする必要がある場合があります。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="@dimen/thumbnail_size"
    android:layout_height="@dimen/thumbnail_size"
    android:layout_margin="5dp"
    android:gravity="center"
    android:orientation="vertical"
     >

    <ImageView
        android:id="@+id/thumbnail"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_margin="4dp"
        android:scaleType="fitXY" />

    <ImageView
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/pixel_frame"
        android:scaleType="fitXY" />

</FrameLayout>
于 2012-06-21T10:07:35.530 に答える
4

簡単な解決策の 1 つは、コンテナである image2に 1 つだけImageViewを使用し、実際のイメージである image1 に1 つだけを使用することです。android:backgroundandroid:src

<ImageView
    ...
    android:background="@drawable/image2"
    android:src="@drawable/image1"
    android:padding="2dp" />

パディングを追加して、「フレーム」と実際の「画像」の間にどれだけの空きスペースを残したいかを指定します。

于 2012-06-21T07:29:12.207 に答える
3

ImageButton を使用します。 背景を Image1 に、Image src を Image2 に設定します。

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/image2"
            android:src="@drawable/image1" />
于 2012-06-21T07:30:27.650 に答える