【问题标题】:Android ?attr/selectableItemBackgroundBorderless look squared instead of circleAndroid ?attr/selectableItemBackgroundBorderless 看起来是方形而不是圆形
【发布时间】:2018-02-23 03:34:22
【问题描述】:

我正在使用 Android 支持库版本 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

PIC 2

【问题讨论】:

  • 它看起来已经越界了。您在哪个 API 级别上进行了测试?
  • 显示您的代码。
  • 显示你的xml代码
  • 我已经更新了我的问题。
  • 你解决了这个问题吗?

标签: android material-design android-imagebutton


【解决方案1】:

我真的不android:hardwareAccelerated="false" Manifest.xml 上的所有 ?attr/selectableItemBackgroundBorderless 都坏了。

为了解决这个问题,我只是从application 标记中删除了android:hardwareAccelerated="false"

【讨论】:

    【解决方案2】:

    你需要在ImageButton中给layout_margin

    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" />
    

    【讨论】:

    • OP 想要无限的涟漪。
    • 不幸的是,android:attr/selectableItemBackground 使我的ImageButton 平方。我希望它像 PIC 2 上的圆圈一样。
    • 其他依赖项是否可能在android:attr/selectableItemBackground 上产生平方波纹?因为这是正常的(圆圈波纹)。如果可能,那么如何跟踪导致此问题的第 3 方依赖项?
    猜你喜欢
    • 1970-01-01
    • 2015-09-01
    • 1970-01-01
    • 2019-10-29
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    相关资源
    最近更新 更多