Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: How to change dynamically size of child views to fit parent view size?
    primarykey
    data
    text
    <p>I have a LinearLayout with 3 or 4 views (Buttons and ImageButtons) inside, and I want that all of them have the same size to fit entirely the layout, like shown in the picture below <img src="https://i.stack.imgur.com/P1Lx7.png" alt="example"> The same thing must be done either in horizontal and in vertical.</p> <p>the xml of the LinearLayout is this:</p> <pre><code> &lt;LinearLayout android:id="@+id/discover_right_action_bar" android:layout_width="64dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_below="@id/top_navi_bar" android:background="@color/smart_dark_grey" android:gravity="center" android:orientation="vertical" android:paddingBottom="5dp" android:paddingTop="5dp" &gt; &lt;ImageButton android:id="@+id/home_ib_friend" android:layout_width="60dp" android:layout_height="60dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:saveEnabled="false" android:scaleType="center" android:src="@drawable/ic_action_select_all" /&gt; &lt;ImageButton android:id="@+id/home_ib_camera" android:layout_width="60dp" android:layout_height="60dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:saveEnabled="false" android:scaleType="center" android:src="@drawable/ic_action_camera" /&gt; &lt;ImageButton android:id="@+id/ib_prof_mon_meetings" android:layout_width="60dp" android:layout_height="60dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:saveEnabled="false" android:scaleType="centerInside" android:src="@drawable/clock" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Now I can only set or the size manually in dp, or set it to wrap_content, but than there would be space at the beginning and at the end of the layout.</p> <p>I've tried something with the layout_weight attribute but I don't know well how to use it.</p> <p>I've tried also with getting the real size of the layout (via ViewTreeObserver) and set the size to the internal children but it doesn't work because I couldn't get the real dimension of the layout.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload