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.