我正在使用Android支持lib版本27.0.2。测试API 23. Android selectableItemBackgroundBorderless
曾经是圈子。但就我的情况而言,它的平方我不知道出了什么问题。
`<RelativeLayout
android:id="@+id/vgSharePostHeader"
android:layout_width="match_parent"
android:background="@color/white"
android:layout_height="@dimen/clickable_size_48">
<ImageButton
android:id="@+id/ibSharePostCloseDialog"
android:layout_width="@dimen/clickable_size_32"
android:layout_height="@dimen/clickable_size_32"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/item_gap_l"
android:background="?attr/selectableItemBackgroundBorderless" << HERE
android:src="@drawable/ic_close_black_24dp"
android:tint="@color/gray_text" /> ...
结果如下图所示:
预期结果应为PIC 2
答案 0 :(得分:0)
我真的不android:hardwareAccelerated="false"
Manifest.xml上的所有?attr/selectableItemBackgroundBorderless
都损坏了。
要解决此问题,我只需从android:hardwareAccelerated="false"
标记中删除application
。
答案 1 :(得分:-1)
您需要在layout_margin
ImageButton
layout_margin应大于或等于(√2 * layout_width - layout_width)/2
,以便可以完全绘制selectableItemBackgroundBorderless
。
如果clickable_size_32
为32dp
,则layout_margin
为(√2*32 -32)/2 = 6.8
那么你的ImageView
应该是这样的 -
<ImageButton
android:id="@+id/ibSharePostCloseDialog"
android:layout_width="@dimen/clickable_size_32"
android:layout_height="@dimen/clickable_size_32"
android:layout_centerVertical="true"
android:layout_margin="7dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_close_black_24dp"
android:tint="@color/gray_text" />