In this post, we finally gonna take a look at how to implement onMeasure() properly.
When implementing a custom view, we should always consider its lower and upper size limit. In this case since the format of the time is fixed (hh:mm:ss). So we just need to get the width and height of it.
Suppose we set the MAX_TIME = "00:00:00", then to get its width in pixel we can do:
In Part I, we talked about how to create a simple custom view. But we don’t really implement the onMeasure(). In this post, we will analyze what problems we will have if we omit the onMeasure().
You can think of how the measurements are made as a conversation between the child and parent views.
The child tells its parent how it wants to be laid out by using LayoutParams. This can either be set in xml file or programatically.
Some time ago I read this article about Why Mit Stopped Teaching SICP. Gerry Sussman said that nowadays people do not often need to build something from scratch again, there exists massive and huge library code for nearly everything. So today’s programming work is more like poking around other people’s code until it works.
I’ve beening doing Android dev for some time now, and I have to say that I sadly agree with him.
Creating your own custom android views can be useful and daunting at the same time. For a long time there is nobody really talks about it in a approachable way, until this lady Huyen Tue Dao. Let’s try to follow her approach and create some custom view!
In this part, we will create a very simple timer view that takes up the whole screen and display the current time.
So let’s get started.
While reading Effective Java Item 21: Use function objects to represent strategies, something hit my mind and now I’m writing it down.
All these new lambda thing is really what is called the Strategy pattern in the OOP world, or would it be more appropriate to say that the Strategy Pattern in Design patterns is really what lambda is.
The essence of all these, can be boiled down to one simple idea, pass functionalities around.