android - How to remeasure layout_weight? -


In the layout xml below I am creating horizontal linearLayout with two hair sequences LinearLayout The child is considered to be dynamically spread of its breadth, depending on the height of the parent it has width of ImageView .

  & lt; LinearLayout android: Layout_width = "match_parent" Android: layout_height = "wrap_content" Android: orientation = "horizontal" & gt; & Lt; LinearLayout Android: layout_width = "0dp" Android: layout_height = "wrap_content" Android: layout_weight = "1" Android: orientation = "vertical" & gt; & Lt ;! - Some children ... - & gt; & Lt; / LinearLayout & gt; & Lt; MyAspectRatioImageView Android: layout_width = "wrap_content" Android: layout_height = "match_parent" Android: adjustViewBounds = "true" /> & Lt; / LinearLayout & gt;  

Now, what I am trying to achieve is a result like this:

But what exactly do I get:

The reason for this is that in my custom ImageView in onMeasure is set to 1: Override (simplified) to maintain 1 aspect ratio:

  override def param (width criteria: IT, height measurement: IT) { Super. Match Measure (width, measure, height, measurement) setmented dimensions (height, height)}  

Now I want to see the parents to recalculate the width of the stock with the new image width. Will be required. How can I do this?

For now I have onMeasure which is super Does not call. It has been focused on its extreme scenario and can easily be broken when used elsewhere. Also the code is in Scala, sorry about it.

  override def param (width measurement: int, heightMeasure: int) {getDrawable, getMode (widthMeasure), getMode (heightMeasure)) match {// a drawable case ( None, _) = & gt; Setmated dimensions (0, 0) // Width and height cases are known (_, (absolutely, absolutely)) = & gt; {// Ratio Val (width, height) = ratio. Determine which axis to adjust for getDominance match {case 0 = & gt; (GetSize (width measurement), (getSize (width measurement) * ratio. GetValue) .toInt) Case 1 => GetSize (heightMeasure) * ratio. GetValue) .toInt, getSize (heightMeasure))} setMeasuredDimensions (width, height) // if this call works in the first place (getAdjustViewBounds) {getLayoutParams.width = width getLayoutParams height = height} } // Only height dimension is known, adjust the width in terms of ratio (_, (_, exactly)) => {Val height = getSize (heightMeasure) setMeasuredDimensions ((height * ratio.getValue) .toInt, height)} // Only width dimension is known, adjust height in proportion to ratio (_, (EXACTLY, _)) = Gt; {Val width = getSize (widthMeasure) setmitted dimensions (width = ratio getValue) .toInt, width}} case (some drabable), (unconfirmed, unused))> & gt; {Wall (width, height) = ratio. Gate amitine match {case 0 = & gt; (Drawable.getIntrinsicWidth, (drawable.getIntrinsicWidth * ratio. GetValue) .toInt) Case 1 = & gt; (Drawable.getIntrinsicHeight * ratio.getValue) .toInt, drawable.getIntrinsicHeight)} Set dimension (width, height)} case (some (drawable), (disagree, _)) = & gt; {SetMeasuredDimensions ((drawable.getIntrinsicWidth * ratio.getValue) .toInt, drawable.getIntrinsicWidth)} case (some (drawable), (_, disagree)) = & gt; {SetMeasuredDimensions ((drawable.getIntrinsicHeight * ratio.getValue) .toInt, drawable.getIntrinsicHeight)} _Status = _ Super.onMeasure (width measure, height)}}  


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -