Android:展开ImageView可点击区域

Android:展开ImageView可点击区域,android,click,imageview,Android,Click,Imageview,我有一个小图像显示在一个线性布局中,在它的右边和左边有一些空白。 我的问题是边距不可点击。 如何在视图的右侧和左侧显示空间,并使用此额外空间扩展可单击区域 <ImageButton android:id="@+id/markReadButton" android:layout_width="22dp" android:layout_height="22dp" android:layout_marginLeft="15dp" android:layou

我有一个小图像显示在一个线性布局中,在它的右边和左边有一些空白。 我的问题是边距不可点击。 如何在视图的右侧和左侧显示空间,并使用此额外空间扩展可单击区域

<ImageButton
    android:id="@+id/markReadButton"
    android:layout_width="22dp"
    android:layout_height="22dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:adjustViewBounds="true"
    android:background="@android:drawable/checkbox_on_background"
    android:gravity="center_vertical"
    android:onClick="onMarkRead" >
</ImageButton>

我认为使用填充代替边距将允许您为您的项目提供更多空间,同时也允许其可点击

看一下边距与填充的描述:

编辑: 尝试对图像使用android:src,设置android:background=“@null”,并增加ImageButton对象的总体大小。在这一点上,我甚至不确定你是否需要填充物。您可以根据需要使用位于ImageButton中心的src图像修改高度和宽度

    <ImageButton
        android:id="@+id/markReadButton"
        android:layout_width="60dp"
        android:layout_height="40dp"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:src="@android:drawable/checkbox_on_background"
        android:background="@null"
        android:adjustViewBounds="true"
        android:onClick="onMarkRead"
    />

这是在Google IO 2011 Schenduling应用程序中使用TouchDelegate完成的。看看像这样使用它的活动

// Larger target triggers star toggle
final View starParent = mRootView.findViewById(R.id.header_session);
FractionalTouchDelegate.setupDelegate(starParent, mStarred, new RectF(0.6f, 0f, 1f, 0.8f));
。它是开源的,应该很容易导入到您的项目中


祝你好运,希望这有帮助

只需添加布局父级,并将eg 20dp设置为更大的宽度和高度大小

<RelativeLayout android:id="@+id/relativeLayoutButton"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:paddingRight="20dp"
        android:paddingLeft="20dp" >

<ImageButton
    android:id="@+id/markReadButton"
    android:layout_width="22dp"
    android:layout_height="22dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:adjustViewBounds="true"
    android:background="@android:drawable/checkbox_on_background"
    android:gravity="center_vertical"
    android:onClick="onMarkRead" >
</ImageButton>

然后设置布局和图像的相同位置。
同样设置可点击的布局和按钮

看起来还有一些额外的事情要做,才能让填充像你想要的那样工作。您可以使用src值设置图像并将背景设置为@null。增加ImageButton对象的总宽度将为您提供所需的大小。