一款汇总了郭霖,鸿洋,以及自己平时收集的自定义控件集合库(小红书)
想了解更多大厂炫酷控件,请关注微信公众号:控件人生
博客地址:Android自定义控件进阶篇,自定义LayoutManager
博客地址:Android控件人生第一站,小红书任意拖拽标签控件
博客地址:第一站小红书图片裁剪控件之二,自定义CoordinatorLayout联动效果
一款汇总了郭霖,鸿洋,以及自己平时收集的自定义控件的集合库。主旨帮助大家学习自定义控件中的一些技巧,分析问题解决问题的一种思路。
root build.gradle
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
app build.gradle
dependencies {
implementation 'com.github.HpWens:MeiWidgetView:v0.1.6'
}
<com.meis.widget.MeiTextPathView
...
android:layout_width="match_parent"
android:layout_height="wrap_content"/> <declare-styleable name="MeiTextPathView">
<attr name="text" format="string"/>
<attr name="textSize" format="dimension"/>
<attr name="textColor" format="color"/>
<attr name="duration" format="integer"/>
<attr name="strokeWidth" format="dimension"/>
<attr name="cycle" format="boolean"/>
<attr name="autoStart" format="boolean"/>
</declare-styleable>
<com.meis.widget.ball.BounceBallView
...
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.meis.widget.MeiRippleView
...
android:layout_width="match_parent"
android:layout_height="wrap_content" /> /**
* @param startX 被点击view相对屏幕的 view中心点x坐标
* @param startY 被点击view相对屏幕的 view中心点y坐标
* @param startRadius 开始扩散的半径
*/
public void startRipple(int startX, int startY, int startRadius)Android自定义View实现炫酷的主题切换动画(仿酷安客户端)
<com.meis.widget.MeiLinePathView
...
android:layout_width="match_parent"
android:layout_height="wrap_content" /> //设置路径
public void setPath(Path path) {
mKeyframes = new Keyframes(path);
mAlpha = 0;
}
<com.meis.widget.MeiScrollParallaxView
...
android:layout_width="match_parent"
android:layout_height="wrap_content"/> <declare-styleable name="MeiScrollParallaxView">
<attr name="parallaxRate" format="float"/>
<attr name="enableParallax" format="boolean"/>
<attr name="roundWidth" format="dimension"/>
<attr name="enableCircle" format="boolean"></attr>
<attr name="outRoundColor" format="color"/>
</declare-styleable>打造丝滑的滑动视差控件(ScrollParallaxView)
<com.meis.widget.heart.MeiHeartView
...
android:layout_width="match_parent"
android:layout_height="wrap_content"/> <declare-styleable name="MeiHeartView">
<attr name="heartDuration" format="integer"/>
<attr name="heartEnableAlpha" format="boolean"/>
<attr name="heartEnableScale" format="boolean"/>
</declare-styleable>
通过 xml 布局的方式替换掉 selector 文件 , 这么做的优势在于 , 减少 apk 体积 , 避免后期维护大量的 selector 文件 , 扩展性更强 , 易修改 , 直观 , 功能更加强大
委托的扩展方式(Delegate), 参考的是(AppCompatActivity实现方式), 具体请参考(RadiusTextView)
…`
…`
针对头条效果做了如下优化
<com.meis.widget.photodrag.VideoDragRelativeLayout
...
android:layout_width="match_parent"
android:layout_height="match_parent"/>…`
VideoDragRelativeLayout 继承 RelativeLayout 默认拦截并消费事件 , 若子控件想消费事件请在 xml 布局文件中设置子控件 android:tag="dispatch"
public interface OnVideoDragListener {
//开始拖拽
void onStartDrag();
/**
* 释放拖拽
* @param isRestoration 是否恢复 true 则执行恢复动画 false 则执行结束动画
*/
void onReleaseDrag(boolean isRestoration);
/**
* 动画结束
* @param isRestoration 是否恢复 true 执行的恢复动画结束 false执行的结束动画结束
*/
void onCompleteAnimation(boolean isRestoration);
}基于jbox2d引擎实现 , 文中有相应的代码注释请查阅
<com.meis.widget.mobike.MoBikeView
android:layout_width="0dp"
android:layout_height="0dp"
...
/>
<com.meis.widget.rose.RoseGiftSurfaceView
android:id="@+id/rose"
android:layout_width="0dp"
android:layout_height="0dp"
... /> mRoseGiftSurfaceView.startAnimation();通过三阶贝塞尔曲线,绘制每个粒子的运动轨迹
<com.meis.widget.particle.FireflyView
android:id="@+id/firfly"
android:layout_width="0dp"
android:layout_height="0dp"
... /> <declare-styleable name="FireflyView">
<attr name="firefly_num" format="integer"></attr>
<attr name="firefly_max_radius" format="integer"></attr>
<attr name="firefly_move_rate" format="integer"></attr>
</declare-styleable>贝塞尔曲线来计算点赞小图标的位置
// 初始化
mPraiseAnimator = new BezierPraiseAnimator(this);
// 开始动画
mPraiseAnimator.startAnimation(mIvPraise);一款炫酷的文本跳动控件
文章博客地址:一篇文本跳动控件,为你打开一扇大门,学会这两点心得,控件你也会写
文章博客地址:仿豆瓣弹性滑动控件,史上最全方位讲解事件滑动冲突
QQ群:478720016
欢迎发邮件或者提issue
Copyright 2018 文淑
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.No open issues yet, or sync has not completed.