Android?attr / selectableItemBackgroundBorderless看起来是方形而不是圆形

时间:2018-02-23 03:34:22

标签: android material-design android-imagebutton

我正在使用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" /> ...

结果如下图所示:

enter image description here

预期结果应为PIC 2

PIC 2

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_3232dp,则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" />