Nested weights warning












0















I get this warning on my layout in Android Studio:




Nested weights are bad for performance less...
Layout weights require
a widget to be measured twice. When a LinearLayout with non-zero
weights is nested inside another LinearLayout with non-zero weights,
then the number of measurements increase exponentially.
Issue id:
NestedWeights




activity_main.xml:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
style="?android:attr/buttonBarStyle">
<Button
android:id="@+id/b1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#093A3E"
android:foreground="?attr/selectableItemBackground"
android:text="One"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
<Button
android:id="@+id/b2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#3AAFB9"
android:foreground="?attr/selectableItemBackground"
android:text="Two"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
style="?android:attr/buttonBarStyle">
<Button
android:id="@+id/b6"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:foreground="?attr/selectableItemBackground"
android:layout_weight="1"
android:background="#64E9EE"
android:text="Three"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
<Button
android:id="@+id/b7"
android:layout_width="0dp"
android:layout_height="match_parent"
android:foreground="?attr/selectableItemBackground"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#97C8EB"
android:text="Four"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
</LinearLayout>
</LinearLayout>


Result:
enter image description here



How can I avoid this warning and get the same result? Thanks.










share|improve this question


















  • 1





    Don't worry. Only 2 levels deep is nothing.

    – forpas
    Nov 27 '18 at 15:34
















0















I get this warning on my layout in Android Studio:




Nested weights are bad for performance less...
Layout weights require
a widget to be measured twice. When a LinearLayout with non-zero
weights is nested inside another LinearLayout with non-zero weights,
then the number of measurements increase exponentially.
Issue id:
NestedWeights




activity_main.xml:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
style="?android:attr/buttonBarStyle">
<Button
android:id="@+id/b1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#093A3E"
android:foreground="?attr/selectableItemBackground"
android:text="One"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
<Button
android:id="@+id/b2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#3AAFB9"
android:foreground="?attr/selectableItemBackground"
android:text="Two"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
style="?android:attr/buttonBarStyle">
<Button
android:id="@+id/b6"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:foreground="?attr/selectableItemBackground"
android:layout_weight="1"
android:background="#64E9EE"
android:text="Three"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
<Button
android:id="@+id/b7"
android:layout_width="0dp"
android:layout_height="match_parent"
android:foreground="?attr/selectableItemBackground"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#97C8EB"
android:text="Four"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
</LinearLayout>
</LinearLayout>


Result:
enter image description here



How can I avoid this warning and get the same result? Thanks.










share|improve this question


















  • 1





    Don't worry. Only 2 levels deep is nothing.

    – forpas
    Nov 27 '18 at 15:34














0












0








0








I get this warning on my layout in Android Studio:




Nested weights are bad for performance less...
Layout weights require
a widget to be measured twice. When a LinearLayout with non-zero
weights is nested inside another LinearLayout with non-zero weights,
then the number of measurements increase exponentially.
Issue id:
NestedWeights




activity_main.xml:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
style="?android:attr/buttonBarStyle">
<Button
android:id="@+id/b1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#093A3E"
android:foreground="?attr/selectableItemBackground"
android:text="One"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
<Button
android:id="@+id/b2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#3AAFB9"
android:foreground="?attr/selectableItemBackground"
android:text="Two"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
style="?android:attr/buttonBarStyle">
<Button
android:id="@+id/b6"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:foreground="?attr/selectableItemBackground"
android:layout_weight="1"
android:background="#64E9EE"
android:text="Three"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
<Button
android:id="@+id/b7"
android:layout_width="0dp"
android:layout_height="match_parent"
android:foreground="?attr/selectableItemBackground"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#97C8EB"
android:text="Four"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
</LinearLayout>
</LinearLayout>


Result:
enter image description here



How can I avoid this warning and get the same result? Thanks.










share|improve this question














I get this warning on my layout in Android Studio:




Nested weights are bad for performance less...
Layout weights require
a widget to be measured twice. When a LinearLayout with non-zero
weights is nested inside another LinearLayout with non-zero weights,
then the number of measurements increase exponentially.
Issue id:
NestedWeights




activity_main.xml:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
style="?android:attr/buttonBarStyle">
<Button
android:id="@+id/b1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#093A3E"
android:foreground="?attr/selectableItemBackground"
android:text="One"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
<Button
android:id="@+id/b2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#3AAFB9"
android:foreground="?attr/selectableItemBackground"
android:text="Two"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
style="?android:attr/buttonBarStyle">
<Button
android:id="@+id/b6"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:foreground="?attr/selectableItemBackground"
android:layout_weight="1"
android:background="#64E9EE"
android:text="Three"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
<Button
android:id="@+id/b7"
android:layout_width="0dp"
android:layout_height="match_parent"
android:foreground="?attr/selectableItemBackground"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#97C8EB"
android:text="Four"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp"
style="?android:attr/buttonBarButtonStyle" />
</LinearLayout>
</LinearLayout>


Result:
enter image description here



How can I avoid this warning and get the same result? Thanks.







android android-studio android-layout warnings






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 27 '18 at 15:30









Simone RomaniSimone Romani

618




618








  • 1





    Don't worry. Only 2 levels deep is nothing.

    – forpas
    Nov 27 '18 at 15:34














  • 1





    Don't worry. Only 2 levels deep is nothing.

    – forpas
    Nov 27 '18 at 15:34








1




1





Don't worry. Only 2 levels deep is nothing.

– forpas
Nov 27 '18 at 15:34





Don't worry. Only 2 levels deep is nothing.

– forpas
Nov 27 '18 at 15:34












1 Answer
1






active

oldest

votes


















1














For better approach i posted the code below using ConstraintLayout



For your approach here is the solution
Remove from layouts android:layout_weight="1"



You should have reformat your code in the following order.




  1. LinearLayout (root) orientation vertical (containing 2 other LinearLayouts)

  2. LinearLayout (top, inside root) orientation horizontal ( with button weights to 1)

  3. LinearLayout (bottom,inside root) orientation horizontal( with button weights to 1)


Better approach would be Using ConstraintLayout



enter image description here



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent">

<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="1"
app:layout_constraintBottom_toTopOf="@+id/button4"
app:layout_constraintEnd_toStartOf="@+id/button3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button5"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/button4"
app:layout_constraintTop_toBottomOf="@+id/button3" />

<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button2" />

<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="2"
app:layout_constraintBottom_toTopOf="@+id/button5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/button2"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53502977%2fnested-weights-warning%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    For better approach i posted the code below using ConstraintLayout



    For your approach here is the solution
    Remove from layouts android:layout_weight="1"



    You should have reformat your code in the following order.




    1. LinearLayout (root) orientation vertical (containing 2 other LinearLayouts)

    2. LinearLayout (top, inside root) orientation horizontal ( with button weights to 1)

    3. LinearLayout (bottom,inside root) orientation horizontal( with button weights to 1)


    Better approach would be Using ConstraintLayout



    enter image description here



    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <Button
    android:id="@+id/button2"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:text="1"
    app:layout_constraintBottom_toTopOf="@+id/button4"
    app:layout_constraintEnd_toStartOf="@+id/button3"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

    <Button
    android:id="@+id/button5"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:text="4"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/button4"
    app:layout_constraintTop_toBottomOf="@+id/button3" />

    <Button
    android:id="@+id/button4"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:text="3"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/button5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/button2" />

    <Button
    android:id="@+id/button3"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:text="2"
    app:layout_constraintBottom_toTopOf="@+id/button5"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/button2"
    app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>





    share|improve this answer






























      1














      For better approach i posted the code below using ConstraintLayout



      For your approach here is the solution
      Remove from layouts android:layout_weight="1"



      You should have reformat your code in the following order.




      1. LinearLayout (root) orientation vertical (containing 2 other LinearLayouts)

      2. LinearLayout (top, inside root) orientation horizontal ( with button weights to 1)

      3. LinearLayout (bottom,inside root) orientation horizontal( with button weights to 1)


      Better approach would be Using ConstraintLayout



      enter image description here



      <?xml version="1.0" encoding="utf-8"?>
      <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent" android:layout_height="match_parent">

      <Button
      android:id="@+id/button2"
      android:layout_width="0dp"
      android:layout_height="0dp"
      android:layout_marginStart="8dp"
      android:layout_marginEnd="8dp"
      android:layout_marginBottom="8dp"
      android:text="1"
      app:layout_constraintBottom_toTopOf="@+id/button4"
      app:layout_constraintEnd_toStartOf="@+id/button3"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent" />

      <Button
      android:id="@+id/button5"
      android:layout_width="0dp"
      android:layout_height="0dp"
      android:layout_marginStart="8dp"
      android:layout_marginTop="8dp"
      android:layout_marginEnd="8dp"
      android:layout_marginBottom="8dp"
      android:text="4"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toEndOf="@+id/button4"
      app:layout_constraintTop_toBottomOf="@+id/button3" />

      <Button
      android:id="@+id/button4"
      android:layout_width="0dp"
      android:layout_height="0dp"
      android:layout_marginStart="8dp"
      android:layout_marginTop="8dp"
      android:layout_marginEnd="8dp"
      android:layout_marginBottom="8dp"
      android:text="3"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@+id/button5"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/button2" />

      <Button
      android:id="@+id/button3"
      android:layout_width="0dp"
      android:layout_height="0dp"
      android:layout_marginStart="8dp"
      android:layout_marginTop="8dp"
      android:layout_marginEnd="8dp"
      android:layout_marginBottom="8dp"
      android:text="2"
      app:layout_constraintBottom_toTopOf="@+id/button5"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toEndOf="@+id/button2"
      app:layout_constraintTop_toTopOf="parent" />

      </android.support.constraint.ConstraintLayout>





      share|improve this answer




























        1












        1








        1







        For better approach i posted the code below using ConstraintLayout



        For your approach here is the solution
        Remove from layouts android:layout_weight="1"



        You should have reformat your code in the following order.




        1. LinearLayout (root) orientation vertical (containing 2 other LinearLayouts)

        2. LinearLayout (top, inside root) orientation horizontal ( with button weights to 1)

        3. LinearLayout (bottom,inside root) orientation horizontal( with button weights to 1)


        Better approach would be Using ConstraintLayout



        enter image description here



        <?xml version="1.0" encoding="utf-8"?>
        <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent" android:layout_height="match_parent">

        <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="1"
        app:layout_constraintBottom_toTopOf="@+id/button4"
        app:layout_constraintEnd_toStartOf="@+id/button3"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

        <Button
        android:id="@+id/button5"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="4"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button4"
        app:layout_constraintTop_toBottomOf="@+id/button3" />

        <Button
        android:id="@+id/button4"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="3"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/button5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button2" />

        <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="2"
        app:layout_constraintBottom_toTopOf="@+id/button5"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button2"
        app:layout_constraintTop_toTopOf="parent" />

        </android.support.constraint.ConstraintLayout>





        share|improve this answer















        For better approach i posted the code below using ConstraintLayout



        For your approach here is the solution
        Remove from layouts android:layout_weight="1"



        You should have reformat your code in the following order.




        1. LinearLayout (root) orientation vertical (containing 2 other LinearLayouts)

        2. LinearLayout (top, inside root) orientation horizontal ( with button weights to 1)

        3. LinearLayout (bottom,inside root) orientation horizontal( with button weights to 1)


        Better approach would be Using ConstraintLayout



        enter image description here



        <?xml version="1.0" encoding="utf-8"?>
        <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent" android:layout_height="match_parent">

        <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="1"
        app:layout_constraintBottom_toTopOf="@+id/button4"
        app:layout_constraintEnd_toStartOf="@+id/button3"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

        <Button
        android:id="@+id/button5"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="4"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button4"
        app:layout_constraintTop_toBottomOf="@+id/button3" />

        <Button
        android:id="@+id/button4"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="3"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/button5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button2" />

        <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="2"
        app:layout_constraintBottom_toTopOf="@+id/button5"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button2"
        app:layout_constraintTop_toTopOf="parent" />

        </android.support.constraint.ConstraintLayout>






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 27 '18 at 15:50

























        answered Nov 27 '18 at 15:34









        Sz-Nika JanosSz-Nika Janos

        467216




        467216
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53502977%2fnested-weights-warning%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks