0

ビットマップの一部をクリック可能にしたいのですが、レイアウトは次のようになります。

________________________________
|             #####             |
|             #####             |
|      ___________________      |
|      |                 |      |
|      |                 |      |
|      |      image      |      |
|      |                 |      |
|      |                 |      |
|      ___________________      |
________________________________

これを行う最も簡単な方法は、相対的なレイアウトで画像の上にボタンを配置することだと思いました。

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/ImageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ImageView>

    <Button
        android:id="@+id/Button"
        android:layout_width="200dip"
        android:layout_height="150dip"/>
</RelativeLayout>

しかし、ボタンを画像の左上隅に揃える方法がわかりません(現在のように相対的なレイアウトの左上隅ではなく)。これは相対レイアウトで可能ですか?

http://blahti.wordpress.com/2012/06/26/images-with-clickable-areas/ しかし、私の単純な長方形の領域には少しやり過ぎのようです。

4

3 に答える 3

1

これを試して:

    <ImageView
        android:id="@+id/ImageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ImageView>

    <Button
        android:id="@+id/Button"
        android:layout_alignLeft="@id/ImageView"
        android:layout_alignTop = "@id/ImageView"
        android:layout_width="200dip"
        android:layout_height="150dip"/>
</RelativeLayout>
于 2013-02-07T15:03:41.790 に答える
1

使用することもできます

<Button
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@drawable/image1" 
        android:drawableLeft="@drawable/image2t"
        android:drawableRight="@drawable/image3"
        android:drawableTop="@drawable/image4"
        android:drawableTop="@drawable/image4"
        android:textColor="#ffffff"
        />
于 2014-08-02T10:43:15.120 に答える
0

さて、私のgoogle-fuは改善され、asenovmのおかげで私はそれを理解しました! imageview には android:adjustViewBounds プロパティがあり、デフォルトでは false に設定されています。true に設定すると、imageviews の境界が画像に合わせて調整されるため、ボタンに対して alignLeft と alignTop が正しく機能します。

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/ImageView"
        android:layout_centerInParent="true" 
        android:adjustViewBounds="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ImageView>

    <Button
        android:id="@+id/Button"
        android:layout_alignLeft="@id/ImageView"
        android:layout_alignTop = "@id/ImageView"
        android:layout_width="200dip"
        android:layout_height="150dip"/>
</RelativeLayout>
于 2013-02-13T05:47:49.750 に答える