android - Controlling nested ViewGroup size in a RelativeLayout: with wrap_content is still matching parent -


i have widget uses percentrelativelayout position 4 imageviews inside it. need percent feature because i’m putting images along 4 sides of box different relative sizes: top child takes ~60 percent of height. have previewed layout , works great, no problem. widget wrap_content w , h (w don’t care much, h important, see.)

i need widget inside larger layout. have parent relativelayout. layout should contain described widget @ top, buttons below it, in linear fashion: |--(group widget)--(text button)--(image button)—-|, ‘|’ indicates should snug parent. (the reason relative want float view @ bottom right.)

so goal is: parent layout should sized predefined size (basically screen, although in full code there more above level - problem occurs isolating @ level), 2 buttons should calculate natural size , use it, percentrelativelayout @ top should take ‘remaining’ height , use children % sizing.

in practice, screenshot shows (from layout preview tool) - percentrelativelayout sucks size.

in short, can pin sequence of views in relative layout , have variable child? in ios pin first view parent top, last view parent bottom, , thing above it, buttons have intrinsic size , mystery widget sucks remainder.

<relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#f2dce8ff" android:layout_margintop="8dp" xmlns:android="http://schemas.android.com/apk/res/android">  <android.support.percent.percentrelativelayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparenttop="true"     xmlns:tools="http://schemas.android.com/tools"     android:animatelayoutchanges="true"     android:id="@+id/matchplay">      <imageview         android:src="@drawable/model_2"         tools:background="#954f47"         app:layout_heightpercent="59%"         app:layout_aspectratio="100%"         android:layout_alignparenttop="true"         android:layout_centerhorizontal="true"         android:adjustviewbounds="false"         android:id="@+id/avatarview1"         android:scaletype="centerinside" />     <imageview         android:src="@drawable/model_2"         tools:background="#ff0000"         app:layout_heightpercent="20%"         app:layout_aspectratio="100%"         app:layout_margintoppercent="2%"         android:layout_below="@id/avatarview1"         android:layout_alignparentleft="true"         android:adjustviewbounds="false"         android:id="@+id/avatarview2"         android:scaletype="centercrop" />     <imageview         android:src="@drawable/model_2"         tools:background="#00ff00"         app:layout_heightpercent="20%"         app:layout_aspectratio="100%"         app:layout_margintoppercent="2%"         android:layout_below="@id/avatarview1"         android:layout_alignparentright="true"         android:adjustviewbounds="false"         android:id="@+id/avatarview3"         android:scaletype="centercrop" />     <imageview         android:src="@drawable/model_2"         tools:background="#0000ff"         app:layout_heightpercent="22%"         app:layout_aspectratio="100%"         android:layout_below="@id/avatarview2"         android:layout_centerhorizontal="true"         android:adjustviewbounds="false"         android:id="@+id/avatarview4"         android:scaletype="centercrop" />  </android.support.percent.percentrelativelayout>  <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="@string/matchplay_add_shout"     android:id="@+id/shoutbutton"     android:enabled="false"     android:layout_centerhorizontal="true"     android:layout_below="@id/matchplay" />  <imagebutton     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/submitbutton"     android:src="@drawable/matchplay_submit"     android:layout_centerhorizontal="true"     android:layout_below="@id/shoutbutton"     android:minwidth="50dp"     android:contentdescription="@string/matchplay_send_contentdesc" />  <imagebutton     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/passbutton"     android:src="@drawable/matchplay_pass"     android:layout_alignparentend="true"     android:layout_alignparentbottom="true"     android:contentdescription="@string/matchplay_pass_contentdesc" /> 

edit: updated code not use alignparentbottom, thinking key issue; instead used alignparenttop. no change. tried using vertical linearlayout @ root. :(

enter image description here way image group widget percentrelativelayout subclass, if need make magic happen overrides there, can that.

i learned things relativelayout beast:

  • child size , location seem go hand in hand. there's no attempt compute sizes separately location.
  • relativelayout doesn't seem second pass measuring. it's quite greedy: when reaches given child decide put it, makes decision , there. maybe there situations does, i'm not sure, they're not common.
  • last, thing ties together: how specify relations matter, because rl computes dependency order width , height; since things depended on sized first, using greedy property above, if child not have fixed size suck whatever remaining space rl offers it. therefore, since arranged things depend on what's above , matchplay root, therefore matchplay sized first.

thus made dependencies backward, things pinned bottom, matchplay last in dependency chain. strange functioning xml below. strange aspect of implementation, , further documentation not state lack of associativity in relative layout_ attrs. (clearly should, because can affect how use relative attrs!)

<relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#f2dce8ff" android:layout_margintop="8dp" xmlns:android="http://schemas.android.com/apk/res/android">  <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="@string/matchplay_add_shout"     android:id="@+id/shoutbutton"     android:layout_above="@+id/submitbutton"     android:layout_margintop="15dp"     android:layout_centerhorizontal="true"     android:enabled="false" />  <imagebutton     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentbottom="true"     android:layout_centerhorizontal="true"     android:id="@+id/submitbutton"     android:src="@drawable/matchplay_submit"     android:minwidth="50dp"     android:contentdescription="@string/matchplay_send_contentdesc" />  <android.support.percent.percentrelativelayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_above="@id/shoutbutton"     xmlns:tools="http://schemas.android.com/tools"     android:animatelayoutchanges="true"     android:id="@+id/matchplay">      <imageview         android:src="@drawable/model_2"         tools:background="#954f47"         app:layout_heightpercent="60%"         app:layout_aspectratio="100%"         app:layout_marginbottompercent="2%"         android:layout_centerhorizontal="true"         android:adjustviewbounds="false"         android:id="@+id/avatarview1"         android:scaletype="centerinside" />     <imageview         android:src="@drawable/model_2"         tools:background="#ff0000"         app:layout_heightpercent="23%"         app:layout_aspectratio="100%"         android:layout_below="@id/avatarview1"         android:adjustviewbounds="false"         android:id="@+id/avatarview2"         android:scaletype="centercrop" />     <imageview         android:src="@drawable/model_2"         tools:background="#00ff00"         app:layout_heightpercent="23%"         app:layout_aspectratio="100%"         android:layout_below="@id/avatarview1"         android:layout_alignparentright="true"         android:adjustviewbounds="false"         android:id="@+id/avatarview3"         android:scaletype="centercrop" />     <imageview         android:src="@drawable/model_2"         tools:background="#0000ff"         app:layout_heightpercent="23%"         app:layout_aspectratio="100%"         android:layout_alignparentbottom="true"         android:layout_centerhorizontal="true"         android:adjustviewbounds="false"         android:id="@+id/avatarview4"         android:scaletype="centercrop" />  </android.support.percent.percentrelativelayout>      <imagebutton         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/passbutton"         android:src="@drawable/matchplay_pass"         android:layout_alignparentright="true"         android:layout_alignparentbottom="true"         android:contentdescription="@string/matchplay_pass_contentdesc" /> 


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -