material ripple
1.0.2
任何问题或拉取请求都不会得到解决。如果需要更改,请考虑分叉您自己的版本。
Android 视图的波纹效果包装器
compile ' com.balysv:material-ripple:1.0.2 '
在下面的小部件上检查最新版本号或访问版本
在View
上使用静态初始化程序(请参阅下面的xml
属性进行自定义)
MaterialRippleLayout . on ( view )
. rippleColor ( Color . BLACK )
. create ();
或者在布局文件中使用MaterialRippleLayout
包装您的View
:
< com .balysv.materialripple.MaterialRippleLayout
android : id = " @+id/ripple "
android : layout_width = " match_parent "
android : layout_height = " wrap_content " >
< Button
android : layout_width = " match_parent "
android : layout_height = " wrap_content "
android : layout_gravity = " center "
android : text = " Button inside a ripple " />
</ com .balysv.materialripple.MaterialRippleLayout>
如果在AdapterView
中使用,则必须将rippleInAdapter
设置为true
在代码中使用 xml 属性或 setter 进行配置:
app : mrl_rippleOverlay = "true" // if true, ripple is drawn in foreground; false - background
app : mrl_rippleColor = "#ff0000" // color of ripple
app : mrl_rippleAlpha = "0.1" // alpha of ripple
app : mrl_rippleDimension = "10dp" // radius of hover and starting ripple
app : mrl_rippleHover = "true" // if true, a hover effect is drawn when view is touched
app : mrl_rippleRoundedCorners = "10dp" // radius of corners of ripples. Note: it uses software rendering pipeline for API 17 and below
app : mrl_rippleInAdapter = "true" // if true, MaterialRippleLayout will optimize for use in AdapterViews
app : mrl_rippleDuration = "350" // duration of ripple animation
app : mrl_rippleFadeDuration = "75" // duration of fade out effect on ripple
app : mrl_rippleDelayClick = "true" // if true, delays calls to OnClickListeners until ripple effect ends
app : mrl_rippleBackground = "#FFFFFF" // background under ripple drawable; used with rippleOverlay="false"
app : mrl_ripplePersistent = "true" // if true, ripple background color persists after animation, until setRadius(0) is called
将OnClickListener
设置为MaterialRippleLayout
:
findViewById ( R . id . ripple ). setOnClickListener ( new View . OnClickListener () {
@ Override public void onClick ( View v ) {
// handle me
}
});
或者,如果在AdapterView
中使用,只需使用OnItemClickListener
对于那些不幸的开发人员需要支持 14 以上的旧版本,有一种方法可以做到。
您还可以将此库与 Jake Wharton 的动画反向移植 (http://nineoldandroids.com/) 一起使用,更改import android.animation.*;
至: import com.nineoldandroids.animation.*;
, import android.util.Property
; import com.nineoldandroids.util.Property;
并且在 MaterialRippleLayout.java 文件中,仅当您使用大于 14 的 api 时才调用函数shouldDelayChildPressedState()
。
巴利斯·瓦伦图克维修斯
Copyright 2015 Balys Valentukevicius
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.