While writing a team project last night, I ran into a problem that wasn't resolved until this morning. . . That is, in the process of obtaining the result after the custom view "turntable" finishes turning, I want to pass the value to a textview in the activity, but my custom view class is not the inner class of the activity, so the properties of the activity cannot be Sharing, it is impossible to get the string corresponding to the sector covering the 0-degree angle when the speed of the turntable is 0, and then set it as the text of the textview. Besides, the UI cannot be updated in the child thread, even if the custom view class is an activity 's inner class, nor can the UI be updated so simply. Because I have written an internal custom view class of an activity before, I think it is very inconvenient to write this time, and the communication between the view and the activity becomes more complicated, but I think it will be better to modularize it and then couple it. After all, this It's not very good to stuff all the class code into the activity. Speaking of UI cannot be updated in the sub-thread, well, if I put this update in the main thread, there is another problem: waiting for the speed of the turntable to become 0 is a time-consuming operation, and its implementation is to draw one by one The fan shape is implemented, and the drawing is repeated continuously. After one drawing, the speed decreases (that is, the starting angle of the fan shape increases and becomes smaller). It can be seen that if it is waiting in the main thread of the activity, the main thread will hang up in all likelihood. This problem was solved this morning. Regardless of whether the custom view is an inner class or not, just use thread + broadcast
. To be continued. .
Android custom view and activity value transfer
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325028088&siteId=291194637
Recommended
Ranking