笑脸苦脸表示开关状态的开关按钮。
最近在写一个可爱的果冻动效开关按钮。之后无意中看到一个用笑脸和苦脸表示开关状态的按钮(IOS和Dribbble)。因为都是开关按钮,所以顺手写了一个。这篇文档许多相关功能和之前提到的开关按钮类似,更多信息可以去JellyToggleButton看看。
dependencies {
compile 'com.nightonke:faceofftogglebutton:1.0.0'
}
Demo在此:
这里的背景颜色和View的背景颜色略有不同,可以试着定义背景颜色或者阅读源码来查看其不同之处。
setBackgroundColor(int mBackgroundColor)
app:foBackgroundColor="@color/white"
脸运动到左边的背景颜色和运动到右边的背景颜色。
setLeftBackgroundColor(int mLeftBackgroundColor)
setRightBackgroundColor(int mRightBackgroundColor)
app:foLeftBackgroundColor="@color/gray"
app:foRightBackgroundColor="@color/blue"
左脸颜色和右脸颜色。
setLeftFaceColor(int mLeftFaceColor)
setRightFaceColor(int mRightFaceColor)
app:foLeftFaceColor="@color/white"
app:foRightFaceColor="@color/white"
左脸的眼睛颜色和右脸的眼睛颜色。
setLeftEyeColor(int mLeftEyeColor)
setRightEyeColor(int mRightEyeColor)
app:foLeftEyeColor="@color/gray"
app:foRightEyeColor="@color/blue"
setLeftMouthColor(int mLeftMouthColor)
setRightMouthColor(int mRightMouthColor)
app:foLeftMouthColor="@color/gray"
app:foRightMouthColor="@color/blue"
方法 | 是否有动画 | 是否有监听器 |
---|---|---|
setChecked(boolean checked) |
Y | Y |
setChecked(boolean checked, boolean callListener) |
Y | Y/N |
setCheckedImmediately(boolean checked) |
N | Y |
setCheckedImmediately(boolean checked, boolean callListener) |
N | Y/N |
toggle() |
Y | Y |
toggle(boolean callListener) |
Y | Y/N |
toggleImmediately() |
N | Y |
toggleImmediately(boolean callListener) |
N | Y/N |
fotb0.setOnStateChangeListener(new FaceOffToggleButton.OnStateChangeListener() {
@Override
public void onStateChange(float process, State state, FaceOffToggleButton fotb) {
// process - current process of JTB, between [0, 1]
// state - current state of JTB, it is one of State.LEFT, State.LEFT_TO_RIGHT, State.RIGHT and State.RIGHT_TO_LEFT
// fotb - the FOTB
}
});
setDuration(int duration)
app:foDuration="1000"
setDraggable(boolean draggable)
app:foDraggable="false"
更多相关信息,请查阅这。
setColorChangeType(ColorChangeType mColorChangeType)
app:foColorChangeType="hsv"
// 脸的半径,单位像素
setFaceRadius(float mFaceRadius)
// 控件宽度与脸半径的比值,单位浮点数
setWidthRadiusRatio(float mWidthRadiusRatio)
// 脸和背景的间距,单位像素
setFaceMargin(float mFaceMargin)
app:foFaceRadius="15dp"
app:foWidthRadiusRatio="2.5"
app:foFaceMargin="1dp"
手指拖动的距离和脸移动的距离。
setTouchMoveRatioValue(float ratio)
app:foTouchMoveRatioValue="2"
当脸运动到与上次相同的状态是否调用监听器。
setMoveToSameStateCallListener(boolean callListener)
app:foMoveToSameStateCallListener="false"
- 眼睛和嘴巴运动到终点的缓冲动效。
- 更多表情。
第一版本。
Copyright 2016 Nightonke
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.