• Modify measurement logic
  • Added alignment
  • Added a comment graph to the GraphAdapter
  • Fixed known bugs

Look at the renderings first




likeview.gif

Method of use

Layout configuration


Copy the code

Note that there is generally no need to specify the width and height directly; it is automatically measured internally according to the font size

Code configuration

// Like view Settings holder.like.setActivated(entity.islike); holder.like.setNumber(entity.likeNum); holder.like.setCallback(new LikeView.SimpleCallback() { @Override public void activate(LikeView view) { Snackbar. Make (view, "you think" + entity.name + "nice!" , Snackbar.LENGTH_SHORT).show(); } @override public void deactivate(LikeView) {Snackbar. Make (view, "you" + entity.name + "); , Snackbar.LENGTH_SHORT).show(); }}); Holder.setnumber (entity.mentnum); / / set the graphics adapter holder.com ment. SetGraphAdapter (CommentPathAdapter. GetInstance ()); holder.comment.setCallback(new LikeView.SimpleCallback(){ @Override public boolean onClick(LikeView view) { Snackbar.make(view, "you click" + entity.name + "comment button ", snackbar.length_short).show(); // Return true to intercept the click, instead of using the default click event; }});Copy the code

Custom graphics adapter

public class CommentPathAdapter implements LikeView.GraphAdapter { private static CommentPathAdapter instance; Private static final Float xOffsetScale = 0.06f; Private static final Float yOffsetScale = 0.2f; Public static CommentPathAdapter getInstance() {synchronized (commentpathAdapter.class) {if (null == instance) { instance = new CommentPathAdapter(); } } return instance; @override public Path getGraphPath(LikeView view, int length) {Path Path = new Path(); int dx = (int) (length * xOffsetScale); int dy = (int) (length * yOffsetScale); int w = (int) (length * (1 - xOffsetScale * 2)); int h = (int) (length * (1 - yOffsetScale * 2)); path.moveTo(dx, dy); path.lineTo(dx + w, dy); path.lineTo(dx + w, dy + h); Path. lineTo(dx + (w * 0.35f), dy + h); Path. lineTo(dx + (w * 0.1f), dy + (h * 1.4f)); Path. lineTo(dx + (w * 0.1f), dy + h); path.lineTo(dx, dy + h); path.lineTo(dx, dy); return path; }}Copy the code

Custom Configuration


    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
            
            
            
            
            
            
            
            
        
    

Copy the code

interface

Interface * / / * * * event listeners public interface Callback {/ * * * * * @ param click event listeners view of the current view * @ return return true means don't use the default click event * / Boolean  onClick(LikeView view); /** * activate @param view */ void activate(LikeView); Void deactivate(LikeView); void deactivate(LikeView); Public interface GraphAdapter {/** * get the Path of the graph ** @param view Current view * @param length Return Path with graph */ Path getGraphPath(LikeView view, int length); }Copy the code

The statement

This project is a training project, there may be bugs, please point out any bugs, thank you github address welcome Star