【Quoted from CoorChice's blog】 Introduction Welcome to SuperTextView. This document will show you how to use this control to improve the efficiency of your project construction. SuperTextView inherits from TextView, which can greatly reduce the complexity of layout and make some common effects very easy to implement and efficient. At the same time, it has built-in animation driver. You only need to write Adjuster reasonably, and then startAnim() to see the expected animation effect. It is just a control, so you can integrate it in your project without any effort. Features
Usage Guidelines Supported properties SuperTextView conveniently supports setting attributes directly in XML, and you can see the effect immediately. It is as convenient as using TextView normally.
All of the above properties can be set dynamically in Java. Their values can also be obtained. For example:
Circles and borders To achieve the above effect, you usually need to write and manage a lot of <shape> files. Now you only need to set the SuperTextView directly in xml or code. Not simple rounded corners Different from simple rounded corners, SuperTextView supports precise control of the position of rounded corners. One, two, or three are all fine. Everything is under your control. Magic text stroke Text strokes have never been so easy! Efficient Statechart Different from native Drawable, SuperTextView provides more refined control over Drawable. You can easily specify the size and position of Drawable with just one attribute. I believe you must have felt deeply that to achieve the effect in the above picture, you often need to nest multiple layers of layout (usually 3 layers?). SuperTextView only needs one control, and it can be achieved very simply and efficiently. It can greatly reduce the layout complexity in your App and reduce the drawing time of the view tree. Exploding Adjuster Adjuster is designed to insert some operations in the drawing process of SuperTextView. This is very important. For example, the default implementation of DefaultAdjuster can dynamically adjust the size of the text. Of course, you can use it to achieve a variety of effects. To make the Adjuster take effect, you must call SuperTextView.setAutoAdjust(true) to enable the Adjuster function. Of course, you can stop it at your convenience by calling SuperTextView.setAutoAdjust(false). Also, you need to pay attention to the order of calls, because once SuperTextView.setAutoAdjust(true) is called and the Adjuster is not set, the default DefaultAdjuster (which can dynamically adjust the text size) will be enabled until you set your own Adjuster Drawing of intervention controls To implement an Adjuster, you need to inherit SuperTextView.Adjuster and implement the adjust(SuperTextView v, Canvas canvas) method. Adjuster.adjust() will be called during each drawing process, which means you can intervene in the drawing process of the control from the outside in an incredible way.
Note that if you enable animation, you must be very careful when writing the code in adjuster(). Because the animation will be drawn at 60 frames per second. This means that this method will be called 60 times per second! Therefore, do not repeatedly create objects in this method, or it will jam! The reason is that a large amount of objects in a short period of time will cause [memory jitter], resulting in frequent GC. For related knowledge, you can read my two articles:
Responding to touch events If you override the onTouch(SuperTextView v, MotionEvent event) method of Adjuster, you will be able to get the touch events of SuperTextView. This is an important point. If you want to continue to process the touch events of SuperTextView, you must make onTouch() return true. Otherwise, you can only receive an ACTION_DOWN event, not an event stream.
Such a stunning effect Thanks to the built-in animation driver of SuperTextView, you can combine Adjuster to achieve incredible animation effects. All you need to do is call startAnim() and stopAnim() to start/stop the animation after you have written the Adjuster properly. As you can see, the above effect is achieved through Adjuster. And this plug-and-play design allows you to use a new Adjuster on the same SuperTextView at any time. All you need to do is create a new Adjuster and then call setAdjuster(). Previously, @Alex_Cin wanted to see the Ripple effect, so in RippleAdjuster.java, I demonstrated how to use Adjuster and animation driver to achieve the Ripple effect in the above picture. [RippleAdjuster.java link: https://github.com/chenBingX/SuperTextView/blob/master/app/src/main/java/com/coorchice/supertextview/SuperTextView/Adjuster/RippleAdjuster.java] See, you can implement your own Ripple effect using Adjuster. Specify the level of the Adjuster Adjuster is thoughtfully designed with the function of controlling the effect level. You can specify the drawing level of Adjuster through Adjuster.setOpportunity(Opportunity opportunity). In SuperTextView, the drawing layers are divided into three layers from bottom to top: background layer, Drawable layer, and text layer. Use Opportunity to specify which layer your Adjuster wants to be inserted into.
Diagram of three types of opportunities. The default value is Opportunity.BEFORE_TEXT, which is the example in the second picture. In fact, as long as you want, SuperTextView is equivalent to a canvas, you can freely express your creativity on it. It allows you to focus on creation without worrying about writing useless and troublesome codes. How to get started
Method 1 Add this to your build.gradle:
Method 2 You can clone my [Github repository https://github.com/chenBingX/SuperTextView], then find SuperTextView and attrs.xml under the Library package and copy them to your project. Now, you can start using SuperTextView. Click here to jump to the SuperTextView project address. https://github.com/chenBingX/SuperTextView |
<<: Android custom controls: QQ-like unread message drag effect
>>: Top 10 trends in mobile app development for 2017
I found that someone raised the issue of Baidu sn...
Milk is rich in nutrients Not only rich in protei...
Which mini program company in Shanghai has a bett...
Friends who have bought funds, how are you doing ...
Live streaming e-commerce has experienced rapid g...
Data released by the Ministry of Land, Infrastruc...
Now that short videos have become the traffic ent...
Based on his own practice and what he has learned...
"I will now hand over the control of the ope...
Youcan wrote in the front: This article is an ana...
[[418841]] As the ancients said, "Once a wor...
As the leader of biological evolution, many organ...
There are only two truly effective traffic-genera...
Sogou Promotion PC Multi-Picture Promotion Style ...
Editor: Dong Xiaoxian Reviewer: Zhang Chao, Li Pe...