java - who calls the method TextView.onMeasure(int, int) and give it that two params? -
I want to apply a textView, and I'm overriding the "onMearsure" method, I just have a simple layout , Activity_main, just a linerlayout Xml like this:
& lt; LinearLayout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android .com / tools" android: layout_width = "match_parent" Android: layout_height = "Match_parent" android: orientation = "vertical" & gt; & Lt; / LinearLayout & gt; And I put my TextView in this layout using the Java code. By the way:
protected void onCreate (bundled saved instance) {super.onCreate (savedInstanceState); LinearLayout Route = (LinearLayout) layoutInflator.frame (this) .inflate (R.layout.activity_main, null); SetContentView (root); Ctextview TextView = new Ctextview (this, blank); TextView.setText ("ABCD"); Root.addView (TextView); } And now, I have created some log meager () method, it shows the width mode and height and the mode is exactly AT_MOST. But both the width and height of its parent (linear timepiece) are MATCH_PARENT, so I think the width mode and altitude mode are both AT_MOST.
And I want to know who brings TextView.onMeasure ()? What is its original container?
OK, once the questions are asked when a developer is going to expand the view . / P>
onMeasure () is an opportunity to tell your Android how much you want your custom view to be dependent on the layout constraints provided by parents.
I will tell first. >
I want to highlight a very specific paragraph from this specific article. Drawing layout is a two-pass process: A measure is implemented in the measure (int, int) of measuring pass and layout pass, and the top-down of the view tree is translucal. Each scene pushes the dimension specifications below the tree during the repetition. At the end of the measure, each scene has its measurement stored. The second pass is in the layout (int, int, int, int) and it is also up-down. During this passage, each parent is responsible for using all the measuring sizes of their children.
After reading it it is very easy to understand that whenever your layout appears on the screen. It will be from the root node (parent means child) and whenever your view is attracting, it will check the available space and will trigger the Major with the necessary specification. I think that will help.
Sorry, after going through the source code of the linear layout, you will get a personalized method of forgetting the answer to your question:
Private Zero Force UniformWidth, Int heightMeasureSpec) {...} which will force your width meter to be fixed look inside the 50 9 row.
Comments
Post a Comment