I'm trying to implement ripple effect in a RelativeLayout
on API 22 but it doesn't show up. However the same ripple works in a Button
.
The code for my ripple drawable is as follows:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#d1c4e9">
<item android:id="@android:id/mask"
android:drawable="@android:color/white" />
<item android:drawable="@drawable/rect"/>
</ripple>
Code for Relative Layout is as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@drawable/ripple">
</RelativeLayout>
After this the ripple is set as a background on Button
and RelativeLayout
. The ripple on button works great but it doesn't show up on the RelativeLayout
at all.
Can anyone tell me what am I doing wrong?
RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).
To center something in a RelativeLayout, you use android:layout_centerInParent="true" on the child. If you try to center several childs, they'll end up under/over each other.
Android Layout TypesLinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.
@filthy_wizard: RelativeLayout is not deprecated.
Adding this attribute android:clickable="true"
works. Tested on Nexus 5
In addition to what Rahunandan said, if you are using appcompat-v7 support library you also need to add
android:background="?attr/selectableItemBackground"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With