I'm writing a custom layout that will manage text.
Before I started implementing the ViewGroup#onMeasure()
method I started to dig the EditText source code, specifically at the EditText#onMeasure()
method. So I came across the BoringLayout
. I read the docs but I didn't find much explanation on it and how to use it in an actual custom implementation. Then my question is how can I use it the right way and when it is really needed.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
BoringLayout
is used to draw text on a view. It is called "boring" because it only handles a single line of left-to-right text without any interesting characters such as emoji. This simplification allows the class to overrideonDraw
with more efficient logic than the default does. Here is the source code if you want to see for yourself.Like
StaticLayout
andDynamicLayout
, theBoringLayout
is also a subclass of the abstractLayout
class. As the documentation says, you probably wouldn't use these classes directly unless you are making your own text handling widget. How do you know if you should be using one of these classes? If you are thinking about usingCanvas.drawText
in your custom view, then you should probably think about using aLayout
. They also eventually callCanvas.drawText
, but they do a lot of other processing beforehand.If you are making your own text widget, then you would only use the
BoringLayout
for single line, simple, left-to-right text. For multi-line and more complex text use aStaticLayout
. And if you need to dynamically change the text after creation, then use aDynamicLayout
.Technically, you can draw text on the canvas with `canvas.drawText("text");
However, text is a very general term and can get extremely complicated : is it LeftToRight or RightToLeft ? is it Ellipsized ? is it single or multiLine ? ...
android.text.Layout is here to handle all this.
the typical way to use it is :