xaml - How to do the image fill the text - the same size always - xamarin.forms -


i trying button image, , each button has text inside...but don't know xamarin forms, i'm beginner , images little while text bigger it...

i using grid...and inside 1 other grid 1 colunm , 1 row each button (image , texts) neet image (that button) size of texts inside it

enter image description here

my xml @ moment:

<!-- buttons grid-->     <grid horizontaloptions="center" margin="20,20,20,20" rowspacing="30" columnspacing="10" backgroundcolor="aquamarine" verticaloptions="fillandexpand">         <grid.rowdefinitions>             <rowdefinition height="auto"/>             <rowdefinition height="auto"/>             <rowdefinition height="auto"/>         </grid.rowdefinitions>         <grid.columndefinitions>             <columndefinition width="*"/>             <columndefinition width="*"/>         </grid.columndefinitions>    <!--one of buttons grid, there 4 others one-->   <grid grid.column="0" grid.row="1" backgroundcolor="gray">             <grid.rowdefinitions>                 <rowdefinition height="*"/>             </grid.rowdefinitions>              <image source="comochegarbtn.png" horizontaloptions="fillandexpand" grid.row="0" grid.column="0">                 <image.gesturerecognizers>                     <tapgesturerecognizer tapped="mapaclique"/>                 </image.gesturerecognizers>             </image>              <stacklayout grid.row="0" grid.column="0"  horizontaloptions="center" verticaloptions="center">                 <image source="location.png" verticaloptions="fillandexpand"/>                 <label text="como chegar" textcolor="white" horizontaloptions="center" style="{binding labelsfont}"/>             </stacklayout>           </grid>         </grid> 

in android solve using wrap_content here, in xamarin forms, don't know how solve gray part grid item size

if need exact size of text width of image have use relativelayout.

in relativelayout image width use relativetoview. similar relative layout in android.

<relativelayout>              <image relativelayout.widthconstraint="{constraintexpression type=type=relativetoview, elementname=mystacklayout,property=width,factor=1}" source="comochegarbtn.png" horizontaloptions="fillandexpand" grid.row="0" grid.column="0">                 <image.gesturerecognizers>                     <tapgesturerecognizer tapped="mapaclique"/>                 </image.gesturerecognizers>             </image>              <stacklayout x:name="mystacklayout" horizontaloptions="center" verticaloptions="center">                 <image source="location.png" verticaloptions="fillandexpand"/>                 <label text="como chegar" textcolor="white" horizontaloptions="center" style="{binding labelsfont}"/>             </stacklayout> </relativelayout> 

using 1 or 2 relative layouts won't affect much. if think can write custom render , create complex button in native layer.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -