1 Star 0 Fork 1

miliun / MeiWidgetView

forked from 4567 / MeiWidgetView 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

Hex.pm Hex.pm

MeiWidgetView

一款汇总了郭霖,鸿洋,以及自己平时收集的自定义控件的集合库。主旨帮助大家学习自定义控件中的一些技巧,分析问题解决问题的一种思路。

引入

Step 1. Add the JitPack repository to your build file

root build.gradle

    allprojects {
        repositories {
            ...
            maven { url "https://jitpack.io" }
        }
    }

Step 2. Add the dependency

app build.gradle

	dependencies {
	       implementation 'com.github.HpWens:MeiWidgetView:v0.1.4'
	}

Download APK

使用

1、文字路径

a、效果预览

b、xml布局

    <com.meis.widget.MeiTextPathView
        ...
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

c、xml属性

    <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>

d、参考文章

文字路径动画控件TextPathView解析

2、弹跳小球

a、效果预览

b、xml布局

    <com.meis.widget.ball.BounceBallView
        ...
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

c、属性

  • bounce_count :小球弹跳次数
  • ball_color:小球颜色
  • ball_count:小球数量
  • ball_radius:小球半径
  • ball_delay:小球出现时间间隔(当小球数大于1时)
  • anim_duration:小球一次动画时长
  • physic_mode : 开启物理效果(下落加速上升减速)
  • random_color: 开启小球颜色随机
  • random_radius: 开启小球大小随机(在基础大小上下浮动)
  • random_path: 开启小球路径随机(在基础路径坐标上下浮动)

d、参考文章

自定义View之小球自由落体弹跳加载控件

3、扩散圆(主题切换)

a、效果预览

b、xml布局

    <com.meis.widget.MeiRippleView
        ...
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

c、相关方法

    /**
     * @param startX      被点击view相对屏幕的 view中心点x坐标
     * @param startY      被点击view相对屏幕的 view中心点y坐标
     * @param startRadius 开始扩散的半径
     */
    public void startRipple(int startX, int startY, int startRadius)

d、参考文章

Android自定义View实现炫酷的主题切换动画(仿酷安客户端)

4、酷炫的路径

a、效果预览

b、xml布局

    <com.meis.widget.MeiLinePathView
        ...
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

c、相关方法

    //设置路径
    public void setPath(Path path) {
        mKeyframes = new Keyframes(path);
        mAlpha = 0;
    }

d、参考文章

Android仿bilibili弹幕聊天室后面的线条动画

5、MEI-图片滚动视差控件

a、效果预览

b、xml布局

    <com.meis.widget.MeiScrollParallaxView
        ...
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>	

c、属性

    <declare-styleable name="MeiScrollParallaxView">
        <!-- 滚动速率 (0~1) 值越大滚动视差越明显 -->
        <attr name="parallaxRate" format="float"/>
        <!-- 滑动是否显示视差 默认 true -->
        <attr name="enableParallax" format="boolean"/>
        <!-- 圆角宽度 默认 0  若通过修改父类来实现 则不需要设置此值-->
        <attr name="roundWidth" format="dimension"/>
        <!-- 是否显示圆形 默认 0  若通过修改父类来实现 则不需要设置此值-->
        <attr name="enableCircle" format="boolean"></attr>
        <!--圆角外的颜色 默认白色  若通过修改父类来实现 则不需要设置此值-->
        <attr name="outRoundColor" format="color"/>
    </declare-styleable>

d、参考文章

打造丝滑的滑动视差控件(ScrollParallaxView)

6、MEI-直播间送爱心

a、效果预览

b、xml布局

    <com.meis.widget.heart.MeiHeartView
        ...
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

c、属性

    <declare-styleable name="MeiHeartView">
        <!--爱心动画时长-->
        <attr name="heartDuration" format="integer"/>
        <!--是否显示透明度动画-->
        <attr name="heartEnableAlpha" format="boolean"/>
        <!--是否显示缩放动画-->
        <attr name="heartEnableScale" format="boolean"/>
    </declare-styleable>

d、参考文章

PathMeasure之直播间送爱心

7、Mei-selector控件集

a、效果预览

通过 xml 布局的方式替换掉 selector 文件 , 这么做的优势在于 , 减少 apk 体积 , 避免后期维护大量的 selector 文件 , 扩展性更强 , 易修改 , 直观 , 功能更加强大

b、特性

  • 支持圆角(单独设定四个角角度,圆角半径是高度的一半)
  • 支持背景Pressed,Disabled,Selected,Checked四种状态切换
  • 支持描边(虚线,四种状态切换)
  • 支持文本(四种状态切换)
  • 支持涟漪(水波纹)
  • 支持leftDrawable,topDrawable,rightDrawable,bottomDrawable四种状态切换

c、支持原生控件

  • RadiusTextView
  • RadiusCheckBox
  • RadiusEditText
  • RadiusFrameLayout
  • RadiusLinearLayout
  • RadiusRelativeLayout

d、扩展

委托的扩展方式(Delegate), 参考的是(AppCompatActivity实现方式), 具体请参考(RadiusTextView)

8、MEI-仿百度浏览器图片拖拽控件

a、效果预览

b、xml布局

//PhotoDragRelativeLayout 继承 RelativeLayout 委托的方式 易扩展
<com.meis.widget.photodrag.PhotoDragRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/pdr_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        app:navigationIcon="@mipmap/ic_arrow_back_white_24dp"
        app:title="仿百度浏览器图片拖拽控件"
        app:titleTextColor="#FFF" />

    <me.relex.photodraweeview.PhotoDraweeView
        android:id="@+id/pdv_photo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar"
        android:src="@mipmap/ic_mei_ripple" />

</com.meis.widget.photodrag.PhotoDragRelativeLayout>

c、相关代码

   mPdrLayout.setDragListener(new PhotoDragHelper().setOnDragListener(new PhotoDragHelper.OnDragListener() {
       @Override
       public void onAlpha(float alpha) {
           //透明度的改变
           mPdrLayout.setAlpha(alpha);
       }
       @Override
       public View getDragView() {
           //返回需要拖拽的view
           return mPdvView;
       }
       @Override
       public void onAnimationEnd(boolean isRestoration) {
           //isRestoration true 执行恢复动画  false 执行结束动画
           if (!isRestoration) {
               finish();
               overridePendingTransition(0, 0);
           }
       }
   }));

9、MEI-仿头条小视频拖拽控件

针对头条效果做了如下优化

  • 列表图片没有完全展示点击的转场动画图片明显变形压缩
  • 详情页往顶部拖拽有明显的卡顿现象

a、效果预览

b、xml布局

<com.meis.widget.photodrag.VideoDragRelativeLayout
    ...
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

c、属性

    <declare-styleable name="VideoDragRelativeLayout">

        <!-- 统一前缀 mei 当前父控件是否拦截事件 默认true-->
        <attr name="mei_self_intercept_event" format="boolean"></attr>

        <!-- 进入动画时长  默认 400 -->
        <attr name="mei_start_anim_duration" format="integer"></attr>

        <!-- 结束动画时长  默认 400 -->
        <attr name="mei_end_anim_duration" format="integer"></attr>

        <!-- 恢复系数有关[0~1] 恢复系数越大则需要拖动越大的距离 -->
        <attr name="mei_restoration_ratio" format="float"></attr>

        <!-- y轴偏移速率 值越大偏移越慢 默认2 -->
        <attr name="mei_offset_rate_y" format="integer"></attr>

        <!-- y轴开始偏移系数 默认0.5 -->
        <attr name="mei_start_offset_ratio_y" format="float"></attr>

        <!-- 开始动画是否进入 默认true -->
        <attr name="mei_start_anim_enable" format="boolean"></attr>

    </declare-styleable>

VideoDragRelativeLayout 继承 RelativeLayout 默认拦截并消费事件 , 若子控件想消费事件请在 xml 布局文件中设置子控件 android:tag="dispatch"

d、回调接口

    public interface OnVideoDragListener {

        //开始拖拽
        void onStartDrag();

        /**
         * 释放拖拽
         * @param isRestoration 是否恢复 true 则执行恢复动画  false 则执行结束动画
         */
        void onReleaseDrag(boolean isRestoration);

        /**
         * 动画结束
         * @param isRestoration 是否恢复 true 执行的恢复动画结束  false执行的结束动画结束
         */
        void onCompleteAnimation(boolean isRestoration);
    }

10、仿膜拜单车贴纸效果

基于jbox2d引擎实现 , 文中有相应的代码注释请查阅

a、效果图

b、xml布局

    <com.meis.widget.mobike.MoBikeView
        android:layout_width="0dp"
        android:layout_height="0dp"
	...   
	/>

11、LOVE玫瑰

a、效果预览

b、xml布局

    <com.meis.widget.rose.RoseGiftSurfaceView
        android:id="@+id/rose"
        android:layout_width="0dp"
        android:layout_height="0dp"
        ... />

c、开始动画

 mRoseGiftSurfaceView.startAnimation();

12、浮动粒子

通过三阶贝塞尔曲线,绘制每个粒子的运动轨迹

请下载apk查看实际效果

b、xml布局

    <com.meis.widget.particle.FireflyView
        android:id="@+id/firfly"
        android:layout_width="0dp"
        android:layout_height="0dp"
        ... />

c、属性

    <declare-styleable name="FireflyView">
        <!-- 浮点粒子数量 默认400 -->
        <attr name="firefly_num" format="integer"></attr>
        <!-- 浮点粒子的最大半径 默认5 -->
        <attr name="firefly_max_radius" format="integer"></attr>
        <!-- 浮点粒子的移动速率 默认5 越大移动越慢 -->
        <attr name="firefly_move_rate" format="integer"></attr>
    </declare-styleable>

13、直播间点赞控件

贝塞尔曲线来计算点赞小图标的位置

b、相关代码

// 初始化
mPraiseAnimator = new BezierPraiseAnimator(this);
// 开始动画
mPraiseAnimator.startAnimation(mIvPraise);

14、文本跳动控件

一款炫酷的文本跳动控件

文章博客地址:一篇文本跳动控件,为你打开一扇大门,学会这两点心得,控件你也会写

15、豆瓣弹性滑动控件

文章博客地址:仿豆瓣弹性滑动控件,史上最全方位讲解事件滑动冲突

Contact

QQ群:478720016

wiki

欢迎发邮件或者提issue

LICENSE

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.
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] 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.

简介

暂无描述 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/miliun/MeiWidgetView.git
git@gitee.com:miliun/MeiWidgetView.git
miliun
MeiWidgetView
MeiWidgetView
master

搜索帮助