{"id":13639995,"url":"https://github.com/fxzou/LikeView","last_synced_at":"2025-04-20T02:32:27.610Z","repository":{"id":158802563,"uuid":"75295716","full_name":"fxzou/LikeView","owner":"fxzou","description":"仿即刻点赞桃心控件","archived":false,"fork":false,"pushed_at":"2023-09-04T07:59:38.000Z","size":8287,"stargazers_count":72,"open_issues_count":2,"forks_count":13,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-22T06:10:44.777Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fxzou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-01T13:36:10.000Z","updated_at":"2024-06-15T01:48:44.901Z","dependencies_parsed_at":null,"dependency_job_id":"9fd0841d-f560-490b-9d12-b985696d9d24","html_url":"https://github.com/fxzou/LikeView","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fxzou%2FLikeView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fxzou%2FLikeView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fxzou%2FLikeView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fxzou%2FLikeView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fxzou","download_url":"https://codeload.github.com/fxzou/LikeView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221146861,"owners_count":16764075,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:01:06.844Z","updated_at":"2025-04-20T02:32:27.575Z","avatar_url":"https://github.com/fxzou.png","language":"Java","funding_links":[],"categories":["点赞按钮"],"sub_categories":[],"readme":"# 仿即刻APP点赞桃心的效果\n## 2016-12-5更新\n- 修改测量逻辑\n- 添加了对齐方式\n- 添加了一个评论图形的GraphAdapter\n- 修改了已知BUG\n\n## 先看效果图\n![](img/likeview.gif)\n## 使用方法\n### 布局配置\n```\n\u003ccn.izouxiang.likeview.LikeView\n            android:id=\"@+id/lv\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            app:number=\"99\"\n            /\u003e\n```\n\u003e 注意,一般不需要直接指定宽高,内部会根据字体大小自动测量\n\n### 代码配置\n```java\n\t\t//点赞view的设置\n\t\tholder.like.setActivated(entity.isLike);\n        holder.like.setNumber(entity.likeNum);\n        holder.like.setCallback(new LikeView.SimpleCallback() {\n            @Override\n            public void activate(LikeView view) {\n                Snackbar.make(view, \"你觉得\" + entity.name + \"很赞!\", Snackbar.LENGTH_SHORT).show();\n            }\n\n            @Override\n            public void deactivate(LikeView view) {\n                Snackbar.make(view, \"你取消了对\" + entity.name + \"的赞!\", Snackbar.LENGTH_SHORT).show();\n            }\n        });\n        //评论view的设置\n        holder.comment.setNumber(entity.commentNum);\n        //设置图形适配器\n        holder.comment.setGraphAdapter(CommentPathAdapter.getInstance());\n        holder.comment.setCallback(new LikeView.SimpleCallback(){\n            @Override\n            public boolean onClick(LikeView view) {\n                Snackbar.make(view, \"你点击\" + entity.name + \"的评论按钮\", Snackbar.LENGTH_SHORT).show();\n                //返回true代表拦截此次点击,不使用默认的点击事件\n                return true;\n            }\n        });\n```\n### 自定义图形适配器\n```java\npublic class CommentPathAdapter implements LikeView.GraphAdapter {\n    private static CommentPathAdapter instance;\n    private static final float xOffsetScale = 0.06f;\n    private static final float yOffsetScale = 0.2f;\n\t//可用单例模式\n    public static CommentPathAdapter getInstance() {\n        synchronized (CommentPathAdapter.class) {\n            if (null == instance) {\n                instance = new CommentPathAdapter();\n            }\n        }\n        return instance;\n    }\n\t//这里绘制你想要的图形\n    @Override\n    public Path getGraphPath(LikeView view, int length) {\n        Path path = new Path();\n        int dx = (int) (length * xOffsetScale);\n        int dy = (int) (length * yOffsetScale);\n        int w = (int) (length * (1 - xOffsetScale * 2));\n        int h = (int) (length * (1 - yOffsetScale * 2));\n        path.moveTo(dx, dy);\n        path.lineTo(dx + w, dy);\n        path.lineTo(dx + w, dy + h);\n        path.lineTo(dx + (w * 0.35f), dy + h);\n        path.lineTo(dx + (w * 0.1f), dy + (h * 1.4f));\n        path.lineTo(dx + (w * 0.1f), dy + h);\n        path.lineTo(dx, dy + h);\n        path.lineTo(dx, dy);\n        return path;\n    }\n}\n```\n## 自定义配置\n```\n\u003cresources\u003e\n    \u003cdeclare-styleable name=\"LikeView\"\u003e\n        \u003c!--当前数值,默认0--\u003e\n        \u003cattr name=\"number\" format=\"integer\"/\u003e\n        \u003c!--数字颜色,默认#888888--\u003e\n        \u003cattr name=\"textColor\" format=\"color\"/\u003e\n        \u003c!--图形外边颜色,默认#888888--\u003e\n        \u003cattr name=\"graphColor\" format=\"color\"/\u003e\n        \u003c!--当前激活时图形颜色,默认#ca5f5f--\u003e\n        \u003cattr name=\"animateColor\" format=\"color\"/\u003e\n        \u003c!--字体大小,决定控件高度以及图形大小,默认14sp--\u003e\n        \u003cattr name=\"textSize\" format=\"dimension\"/\u003e\n        \u003c!--动画时间,默认300--\u003e\n        \u003cattr name=\"animateDuration\" format=\"integer\"/\u003e\n        \u003c!--图形与数字间的距离,默认3dp--\u003e\n        \u003cattr name=\"distance\" format=\"dimension\"/\u003e\n        \u003c!--图形与数字高度的比例,默认1.3--\u003e\n        \u003cattr name=\"graphTextHeightRatio\" format=\"float\"/\u003e\n        \u003c!--图形外边绘制宽度,默认3dp--\u003e\n        \u003cattr name=\"graphStrokeWidth\" format=\"dimension\"/\u003e\n        \u003c!--数字绘制宽度,默认2dp--\u003e\n        \u003cattr name=\"textStrokeWidth\" format=\"dimension\"/\u003e\n        \u003c!--是否激活,默认false--\u003e\n        \u003cattr name=\"isActivated\" format=\"boolean\"/\u003e\n        \u003c!--是否自动测量数字修改后的宽度改变,防止更改状态时控件宽度改变,默认开启--\u003e\n        \u003cattr name=\"autoMeasureMaxWidth\" format=\"boolean\"/\u003e\n        \u003c!--是否不允许取消点赞,默认false--\u003e\n        \u003cattr name=\"notAllowedCancel\" format=\"boolean\"/\u003e\n        \u003c!--对齐方式,前三种默认垂直居中--\u003e\n        \u003cattr name=\"gravity\" format=\"enum\"\u003e\n            \u003c!--居中--\u003e\n            \u003cenum name=\"center\" value=\"1\"/\u003e\n            \u003c!--左对齐--\u003e\n            \u003cenum name=\"left\" value=\"2\"/\u003e\n            \u003c!--右对齐--\u003e\n            \u003cenum name=\"right\" value=\"3\"/\u003e\n            \u003c!--开始点--\u003e\n            \u003cenum name=\"start\" value=\"4\"/\u003e\n        \u003c/attr\u003e\n    \u003c/declare-styleable\u003e\n\u003c/resources\u003e\n```\n## 接口\n```java\n/**\n     * 事件监听接口\n     */\n    public interface Callback {\n        /**\n         * 点击事件监听\n         *\n         * @param view 当前View\n         * @return 返回true则代表不使用默认的点击事件\n         */\n        boolean onClick(LikeView view);\n\n        /**\n         * 变为激活状态\n         *\n         * @param view 当前View\n         */\n        void activate(LikeView view);\n\n        /**\n         * 变为不激活状态\n         *\n         * @param view 当前View\n         */\n        void deactivate(LikeView view);\n    }\n    \n    /**\n     * 获取图形Path接口\n     */\n    public interface GraphAdapter {\n        /**\n         * 获取图形的Path\n         *\n         * @param view   当前View\n         * @param length 可绘制图形区域正方形的边长\n         * @return 带有图形的Path\n         */\n        Path getGraphPath(LikeView view, int length);\n    }\n\n```\n## 声明\n此项目为练手项目,当中可能存在BUG,发现BUG请指出,谢谢\n# License\n```\nCopyright 2016 zFxiang\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffxzou%2FLikeView","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffxzou%2FLikeView","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffxzou%2FLikeView/lists"}