android - Set of ImageButtons to Fill Available Space -


in ui design have region of variable width (depending on display size , orientation). region fill set of square imagebuttons following constraints

  • buttons fill entire width of area , adapt automatically different display orientations , widths
  • exception: buttons not grow beyond maximum size, , left-aligned after that
  • buttons , remain square shape
  • button images rather large (300x300px) , should scaled down fill buttons

for using linearlayout horizontal orientation shown in below xml. linearlayout has layout_height = wrap_content, seems stretch available height, resulting in buttons not being square. also, max_width setting not seem have effect.

how need change xml desired layout?

 <linearlayout      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:orientation="horizontal"      android:id="@+id/layoutimagebuttons">       <imagebutton          android:layout_width="0dp"          android:maxwidth="50dp"          android:layout_height="wrap_content"          android:layout_weight="1"          android:scaletype="fitxy"          android:id="@+id/imagebutton1" />       <imagebutton          android:layout_width="0dp"          android:maxwidth="50dp"          android:layout_height="wrap_content"          android:layout_weight="1"          android:scaletype="fitxy"          android:id="@+id/imagebutton2" />       <imagebutton          android:layout_width="0dp"          android:maxwidth="50dp"          android:layout_height="wrap_content"          android:layout_weight="1"          android:scaletype="fitxy"          android:id="@+id/imagebutton3" />       <imagebutton          android:layout_width="0dp"          android:maxwidth="50dp"          android:layout_height="wrap_content"          android:layout_weight="1"          android:scaletype="fitxy"          android:id="@+id/imagebutton4" />   </linearlayout> 

i suggest you should have different dimensions in values directory different screen sizes height , width imagebutton.

i tried make changes layout can reconfigure require. kindly notice, if increase width of imagebutton irrespective it's height become rectangle square

<linearlayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="horizontal">      <linearlayout         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_margin="4dp"         android:layout_weight="0.25"         android:gravity="center"         android:padding="4dp">          <imagebutton             android:layout_width="50dp"             android:layout_height="50dp"             android:maxheight="50dp"             android:minheight="50dp"             android:scaletype="fitxy" />     </linearlayout>      <linearlayout         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_margin="4dp"         android:layout_weight="0.25"         android:gravity="center"         android:padding="4dp">          <imagebutton             android:layout_width="50dp"             android:layout_height="50dp"             android:maxheight="50dp"             android:minheight="50dp"             android:scaletype="fitxy" />     </linearlayout>      <linearlayout         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_margin="4dp"         android:layout_weight="0.25"         android:gravity="center"         android:padding="4dp">          <imagebutton             android:layout_width="50dp"             android:layout_height="50dp"             android:maxheight="50dp"             android:minheight="50dp"             android:scaletype="fitxy" />     </linearlayout>      <linearlayout         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_margin="4dp"         android:layout_weight="0.25"         android:gravity="center"         android:padding="4dp">          <imagebutton             android:layout_width="50dp"             android:layout_height="50dp"             android:maxheight="50dp"             android:minheight="50dp"             android:scaletype="fitxy" />     </linearlayout>  </linearlayout> 

output

enter image description here


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -