触摸布局时,如何在简单的线性/相对布局中产生涟漪效应?
我已经尝试将布局的背景设置为:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight" >
<item android:drawable="@android:color/white"/>
</ripple>
Run Code Online (Sandbox Code Playgroud)
然而,我只看到纯白色背景,并且在触摸布局时没有涟漪效应.我究竟做错了什么?
编辑:
作为参考,这是我的布局xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="250dp"
android:background="@drawable/test"
android:clickable="true">
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我正在尝试将Ripple Effect添加到RecyclerView的项目中.我在网上看了一下,但找不到我需要的东西.我认为它必须是自定义效果.我已经尝试了android:background属性到RecyclerView本身并将其设置为"?android:selectableItemBackground"但它没有工作:
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:clickable="true"
android:background="?android:selectableItemBackground"
android:id="@+id/recyclerView"
android:layout_below="@+id/tool_bar"/>
Run Code Online (Sandbox Code Playgroud)
这是我试图将效果添加到的RecyclerView:

我希望通过代码从属性中获取指向引用.在我的xml布局中,我可以轻松地获得引用的drawable,如下所示:
android:background="?attr/listItemBackground"
Run Code Online (Sandbox Code Playgroud)
属性引用由我的主题设置.我想看看是否可以通过代码获得引用的drawable.
我可以通过创建样式attr并在自定义视图中读取值来解决这个问题,但在这种情况下,我想弄清楚这是否可行而不做所有这些.我认为这是可能的,但我还没有找到获得该属性参考的方法.
谢谢!
我试图将FloatingActionButton纹波设置为类似于此的东西
从材料设计.
问题是我只得到一个没有波纹的"平面样式",它只是将按钮从我的情况下改变为白色到橙色而没有上面链接中显示的动画.
我在这里听到了答案:
但我的FAB仍然很无聊!
编辑:我目前的代码是:XML:
<android.support.design.widget.FloatingActionButton
android:id="@+id/item_activity_fab"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginRight="16dp"
android:src="@drawable/watch"
app:borderWidth="0dp"
app:elevation="6dp"
app:fabSize="normal"
app:layout_anchor="@id/item_activity_title_background"
app:layout_anchorGravity="top|right|end"
app:pressedTranslationZ="12dp"
app:rippleColor="@android:color/transparent"/>
Run Code Online (Sandbox Code Playgroud)
Java的:
mAddToWatchListFAB.setRippleColor(ContextCompat.getColor(this, R.color.orange_6));
Run Code Online (Sandbox Code Playgroud)
我在FAB上尝试了这种方法,但它似乎没有用.我也尝试了我提供的链接中的步骤
android android-animation material-design floating-action-button
我尝试用来padding增加按钮的触摸区域.我用
<ImageButton
android:paddingRight="32dp"
android:paddingEnd="32dp"
android:id="@+id/confirm_image_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="?selectableItemBackgroundBorderless"
android:src="?attr/confirmIcon" />
Run Code Online (Sandbox Code Playgroud)
点击区域是放大的.但是,selectableItemBackgroundBorderless点击效果不再显示为完美的圆圈.
我尝试用duplicateParentState技术来克服.
<FrameLayout
android:clickable="true"
android:paddingRight="32dp"
android:paddingEnd="32dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true">
<ImageButton
android:duplicateParentState="true"
android:id="@+id/confirm_image_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:src="?attr/confirmIcon" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
现在,
selectableItemBackgroundBorderless圆的效果是一个完美的圆.但是,它似乎有一些奇怪的行为.单击实际区域时ImageButton,不显示圆按效果.
我可以知道为什么会这样,我怎么能克服它?我使用API 26进行了测试.
注意,我试图避免使用TouchDelegate技术,除非我被迫,因为它使我们的代码更复杂.
以下是按钮显示的正确行为Toolbar.
当点击区域位于按钮外时,会显示波纹效果
当点击区域在按钮内时,会显示波纹效果
但是,我不知道他们是如何实现这种行为的.
android android-layout android-view android-drawable rippledrawable
我是Android开发的新手.我正在尝试开发适用于Android的短信应用.我成功阅读了收件箱和联系人并将其显示在一个ListView项目中.现在,我想要实现的是ListView每次点击或触摸或选择这些项目时都会产生连锁反应.我使用listSelector但似乎它不起作用.如果有人可以帮助我,下面是我的代码:
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ListView
android:id="@+id/msglist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="true"
android:listSelector="#777777" />
Run Code Online (Sandbox Code Playgroud)
如何在最低 SDK 版本 14 应用程序中实现与 Android 完全相同的效果?
看起来像背景上的圆形放大动画,还是有更具体的功能?
非常感谢...
我知道我可以设置android:background="?android:attr/selectableItemBackground"为任何视图以从 Android Lollipop 中获得不错的涟漪效果。这对于用户触摸的视图非常有效。但是如果我想在没有用户交互的情况下播放涟漪动画怎么办?
在我的应用程序中,我想通过在此视图上播放涟漪动画来引起对视图的注意。我怎样才能做到这一点?我没有找到获取Animatior涟漪动画对象的方法。那么如何在没有用户交互的情况下从代码中将涟漪动画设置为视图?