Android imitation QQ, wechat chat interface long press the prompt box effect

Let's take a look at the renderings first

How to use

Sample code

It's easy to use

First, new a PromptViewHelper class, then set up a prompt view manager, and finally call the addPrompt method to add view. This view is the view to add the prompt box.

Realization idea

By using QQ and wechat, I feel that popupwindow can meet the needs of the prompt box.

So the general idea is:

1. When the view is loaded successfully, add a long press event to it

2. When the user presses and holds a new popupwindow, it is displayed, and it is set to disappear by clicking the external area

In order to make the upper layer call simple and convenient, I intend to encapsulate the prompt box view into a class, which includes: initial method, binding data, adding events, etc; Based on this consideration, first define an abstract class, and then let the specific implementation class implement the corresponding methods. Let's take a look at this abstract class first.

Note: in an abstract class, there is a property of a location object. What does this location do? Because when displaying the prompt box view, we will consider its display location. This location is an enumeration object, which includes some location information;

This enumeration object contains six location display types, and then an icalculatelocation object will be instantiated according to the type in the constructor. What is icalculatelocation?

It is an interface that provides a calculate method to calculate the X and Y coordinates of the prompt box view. We implement this interface to calculate the coordinates of different positions.

By this time, the general framework has come out; First, we define a promtpviewmanager manager to load the prompt box view, bind data, add events, and then implement different calculation classes through the set location enumeration to calculate the coordinates of different positions, and then create a new popupwindow when displaying. The prompt box view is set to popupwindow through promtpviewmanager, Then get the location enumeration through promtpviewmanager to get the class for calculating coordinates, call the calculate method to get the X and Y coordinates, and then display the popupwindow prompt box through the showatlocation method of popupwindow.

Concrete implementation

First, implement a promtpviewmanager management class

Instantiating view, binding data and adding events have been completed. Now we will calculate the coordinates displayed by view. I have implemented several methods and posted one to see. If you have your own needs for location, you can implement a class replication method yourself.

summary

The above is the whole content of this article. I hope the content of this article can be helpful to your study or work. If you have any questions, you can leave a message.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>