ImageView 覆盖了覆盖按钮的波纹效果

     2023-02-22     179

关键词:

【中文标题】ImageView 覆盖了覆盖按钮的波纹效果【英文标题】:ImageView is covering overlaying button's ripple effect 【发布时间】:2015-03-04 18:34:52 【问题描述】:

我有一个 ImageView 作为相对布局的背景,上面有一个刷新按钮。按钮的涟漪效果被其下方的 ImageView 覆盖。我已经尝试过 FrameLayouts 等,但似乎没有任何帮助。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_drawer"
    android:layout_
    android:layout_
    android:layout_gravity="start"
    android:background="@color/sidebar_bg_color"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView4"
        android:layout_
        android:layout_
        android:layout_alignParentTop="true"
        android:src="@drawable/device_bg" />

    <LinearLayout
        android:layout_
        android:layout_
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:background="?android:attr/selectableItemBackgroundBorderless"
        android:clickable="true"
        android:focusable="true"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView3"
            android:layout_
            android:layout_
            android:src="@drawable/sidebar_refresh" />
    </LinearLayout>

</RelativeLayout>

【问题讨论】:

发布您的涟漪 xml 代码和触发涟漪效应的代码 @prem 我没有使用ripple.xml 我正在使用Android的内置涟漪效应,通过使用android:background="?android:attr/selectableItemBackgroundBorderless" 在我添加下面的ImageView之前它工作正常它。 【参考方案1】:

使用selectableItemBackgroundBorderless,您可以这样做:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_drawer"
    android:layout_
    android:layout_
    android:layout_gravity="start"
    android:background="@android:color/holo_green_light"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView4"
        android:layout_
        android:layout_
        android:layout_alignParentTop="true"
        android:scaleType="fitXY"
        android:src="@drawable/device_bg" />

    <ImageView
        android:layout_
        android:layout_
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/sidebar_refresh" />

    <LinearLayout
        android:layout_
        android:layout_
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true">
        <FrameLayout
            android:layout_weight="1"
            android:layout_
            android:layout_
            android:padding="7dp"
            android:background="@android:color/transparent">
            <ImageView
                android:id="@+id/imageView3"
                android:layout_
                android:layout_
                android:clickable="true"
                android:src="@drawable/sidebar_refresh"
                android:alpha="0"
                android:background="?attr/selectableItemBackgroundBorderless"/>
        </FrameLayout>
    </LinearLayout>

</RelativeLayout>

关键是波纹效果必须有自己的布局(LinearLayout+FrameLayout),然后使用alpha="0"将有波纹的图像设置为透明,以便覆盖实心的图像。

这段代码的问题是:

    您必须对填充进行硬编码。如果没有填充或填充太小,波纹效果将绑定为矩形,而不是圆形。使用公式 48(height/width)/7 计算填充。如果除以 7 不起作用,请减小除数,例如6. 因为它有填充,所以你不能触摸填充来触发波纹效果。如果这是一个小按钮是可以接受的,因为它不明显,但如果它是一个大按钮则很重要。

好消息是在drawable/ripple.xml 中使用ripple 标签模拟selectableItemBackgroundBorderless 有另一种方法:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorPrimary">
    <item android:id="@android:id/mask">

        <shape android:shape="oval">
            <solid android:color="?android:colorPrimary"/>
        </shape>

    </item>
</ripple>

据我观察,它给出了与selectableItemBackgroundBorderless 一样的涟漪效应(除了它没有溢出涟漪),所以你没有理由坚持使用默认的selectableItemBackgroundBorderless

有了这个ripple.xml,这样做:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_drawer"
    android:layout_
    android:layout_
    android:layout_gravity="start"
    android:background="@android:color/holo_green_light"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView4"
        android:layout_
        android:layout_
        android:layout_alignParentTop="true"
        android:scaleType="fitXY"
        android:src="@drawable/device_bg" />

    <ImageView
        android:layout_
        android:layout_
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/sidebar_refresh" />

    <LinearLayout
        android:layout_
        android:layout_
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true">
        <FrameLayout
            android:layout_weight="1"
            android:layout_
            android:layout_
            android:background="@android:color/transparent">
            <ImageView
                android:id="@+id/imageView3"
                android:layout_
                android:layout_
                android:clickable="true"
                android:src="@drawable/ripple" />
        </FrameLayout>
    </LinearLayout>

</RelativeLayout>

唯一改变的是LinearLayout 部分。没有更多的硬编码填充和 alpha 图像。唯一的小问题是点击角落仍然会触发连锁反应。我找到了这个thread,但我还没有尝试过。

即使图像不透明,上述两种方法也有效。

【讨论】:

imageview 上的波纹效果

】imageview上的波纹效果【英文标题】:Rippleeffectoverimageview【发布时间】:2017-05-1220:16:21【问题描述】:为了描述我的问题,我创建了一个小例子。我有带有imageview和textview的线性布局。对于线性布局,我将可绘制的波纹设置为背... 查看详情

悬停时的CSS波纹效果?

...:15【问题描述】:我有一个按钮,我想要一个稍微透明的覆盖层,以便在悬停时“滑过”按钮。有一种叫做“涟漪效应”的东西,您通常可以通过单击按钮来实现。喜欢这里:https://codepen.io/tomma5o/pen/zwyKyaHTML:<divclass="container"&... 查看详情

波纹效果不会超出 ImageView

】波纹效果不会超出ImageView【英文标题】:RippleeffectisnotgoingabovetheImageView【发布时间】:2016-06-0206:31:49【问题描述】:我有一个CustomListView,我在其中显示一些文本并使用Picasso的库显示一个image。我在drawable文件夹中创建了一个xm... 查看详情

ImageView 覆盖了额外的空白区域

】ImageView覆盖了额外的空白区域【英文标题】:ImageViewcoversextrawhitespace【发布时间】:2019-08-2313:29:52【问题描述】:您好,我正在android中创建布局,但问题是。我已经添加了scaleType,@987654324,但所有徒劳无功。请帮忙,我该怎... 查看详情

Android BottomSheet 覆盖了锚定 ImageView 的一半

】AndroidBottomSheet覆盖了锚定ImageView的一半【英文标题】:AndroidBottomSheetcovershalfofanchoredImageView【发布时间】:2019-06-0413:28:14【问题描述】:我有一个CoordinatorLayout,其中我有一个BottomSheet和一个ImageView。这是我的BottomSheett:<inclu... 查看详情

帮我更改一下button点击效果水纹效果。

...上都有水波纹,其实是因为生成的那个水波纹动画层全屏覆盖住了整个页面,由于水波纹层是白色半透明的,所以页面的白色区域下你看不见,有其他颜色的区域都会看见(你可以把body的背景颜色改为除白色外的其他颜色,再... 查看详情

如何给imageview设置水波纹效果

...:自定义View根据实际情况可以选择继承自View、TextView、ImageView或其他这次的实现我们都选择继承view,在实现的过程中我们需要关注如下几个方法:1.onMeasure():最先回调,用于控件的测量;2.onSizeChanged():在onMeasure后面回调,可以拿... 查看详情

使用按钮背景颜色为我的按钮添加波纹效果?

】使用按钮背景颜色为我的按钮添加波纹效果?【英文标题】:Addrippleeffecttomybuttonwithbuttonbackgroundcolor?【发布时间】:2017-02-2120:18:34【问题描述】:我创建了一个按钮,我想为该按钮添加波纹效果!我创建了一个按钮bgXML文件:(... 查看详情

如果 ImageView 包含在不覆盖整个屏幕的 ViewPager 的片段中,是不是可以使 ImageView 覆盖整个屏幕?

】如果ImageView包含在不覆盖整个屏幕的ViewPager的片段中,是不是可以使ImageView覆盖整个屏幕?【英文标题】:IsitpossibletomakeanImageViewcoverthewholescreen,ifit\'scontainedinafragmentinaViewPagerthatdoesn\'tcoverthewholescreen?如果ImageView包含在不覆盖整... 查看详情

覆盖 ImageView 的图像属性时出错

】覆盖ImageView的图像属性时出错【英文标题】:ErrorinoverridingimagepropertyofImageView【发布时间】:2015-05-0104:08:54【问题描述】:如果imageView未解决,我正在尝试覆盖ImageView的getter以返回占位符图像,但我有错误,我不能这样做。为... 查看详情

快速防止图像视图中的图像覆盖

...止图像视图中的图像覆盖【英文标题】:Preventimageoverlayinimageviewswift【发布时间】:2018-11-0914:31:22【问题描述】:我有一个带有图像视图的tableViewCell。即使我清除了imageView并设置了图像,我还是得到了以下意外行为,其中一个图... 查看详情

在所有其他视图上添加覆盖视图

】在所有其他视图上添加覆盖视图【英文标题】:addoverlayviewoverallotherviews【发布时间】:2010-05-1215:10:14【问题描述】:如何添加覆盖所有内容的叠加视图。例如在标签栏控制器和导航控制器上?谢谢【问题讨论】:最后我通过... 查看详情

非按钮视图上的 Android 波纹效果 + 高程

】非按钮视图上的Android波纹效果+高程【英文标题】:AndroidRippleEffect+Elevationonnon-ButtonViews【发布时间】:2015-03-2708:38:51【问题描述】:我正在尝试向LinearLayout添加触摸反馈,该反馈类似于API级别21中的常规按钮反馈,与this示例中... 查看详情

android-如何给imageview设置水波纹效果(代码片段)

1.btn_ripple_mask.xml<?xmlversion="1.0"encoding="utf-8"?><ripplexmlns:android="http://schemas.android.com/apk/res/android"android:color="@andro 查看详情

android-如何给imageview设置水波纹效果(代码片段)

1.btn_ripple_mask.xml<?xmlversion="1.0"encoding="utf-8"?><ripplexmlns:android="http://schemas.android.com/apk/res/android"android:color="@andro 查看详情

覆盖Android中的电源按钮

】覆盖Android中的电源按钮【英文标题】:OverridingthepowerbuttoninAndroid【发布时间】:2012-04-1019:16:24【问题描述】:我正在开发一个应用程序,我需要在按下电源按钮时执行操作,但不幸的是我无法处理按下电源按钮的操作。我尝... 查看详情

UISearchBar 的范围按钮覆盖了第一行结果

】UISearchBar的范围按钮覆盖了第一行结果【英文标题】:UISearchBar\'sscopebuttonsarecoveringthefirstrowofresults【发布时间】:2011-06-2823:40:32【问题描述】:我是第一次使用UISearchBar,但不能完全按照我的意愿行事。当您激活范围按钮时,... 查看详情

圆形图标弹出菜单的正确波纹效果形状

...18【问题描述】:在Flutter中,我想为带有圆形边框的图标按钮设置样式,并让Material波纹效果正常工作,以便波纹效果包含在圆圈中。在下面的代码中,第一个按钮可以正常工作。在第二个(弹出)按钮中,波纹效果延伸到按钮... 查看详情