Stop empty ConstraintLayout from maximum stretching











up vote
3
down vote

favorite
1












When I remove all views from my Constraint layout, I want it to have 0dp height(like wrap_content as it sounds) but it stretches as much as possible.



Is there documented way to do that? I mean besides setting maxHeight to 0 or hiding it.



I've tried app:layout_constrainedHeight="true" with "wrap_content" but it doesnt work.



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

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

</android.support.constraint.ConstraintLayout>











share|improve this question




























    up vote
    3
    down vote

    favorite
    1












    When I remove all views from my Constraint layout, I want it to have 0dp height(like wrap_content as it sounds) but it stretches as much as possible.



    Is there documented way to do that? I mean besides setting maxHeight to 0 or hiding it.



    I've tried app:layout_constrainedHeight="true" with "wrap_content" but it doesnt work.



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

    <android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constrainedHeight="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    </android.support.constraint.ConstraintLayout>











    share|improve this question


























      up vote
      3
      down vote

      favorite
      1









      up vote
      3
      down vote

      favorite
      1






      1





      When I remove all views from my Constraint layout, I want it to have 0dp height(like wrap_content as it sounds) but it stretches as much as possible.



      Is there documented way to do that? I mean besides setting maxHeight to 0 or hiding it.



      I've tried app:layout_constrainedHeight="true" with "wrap_content" but it doesnt work.



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

      <android.support.constraint.ConstraintLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:layout_constrainedHeight="true"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent">

      </android.support.constraint.ConstraintLayout>











      share|improve this question















      When I remove all views from my Constraint layout, I want it to have 0dp height(like wrap_content as it sounds) but it stretches as much as possible.



      Is there documented way to do that? I mean besides setting maxHeight to 0 or hiding it.



      I've tried app:layout_constrainedHeight="true" with "wrap_content" but it doesnt work.



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

      <android.support.constraint.ConstraintLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:layout_constrainedHeight="true"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent">

      </android.support.constraint.ConstraintLayout>








      android android-constraintlayout






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 18 at 17:20

























      asked Nov 18 at 16:46









      NDQuattro

      6329




      6329
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          I was unable to find a proper solution.





          The simplest workaround I came up with is to add an extra view with height=0 and never remove it:



          <?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">

          <android.support.constraint.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@android:color/holo_red_dark"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent">

          <FrameLayout
          android:id="@+id/somethingWithNoHeight"
          android:layout_width="match_parent"
          android:layout_height="0dp" />

          <!--<TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Lorem ipsum" />-->
          </android.support.constraint.ConstraintLayout>
          </android.support.constraint.ConstraintLayout>


          I believe you should fill a bug to be sure that developers know about such a problem






          share|improve this answer

















          • 1




            I also went that way though I see here two inconveniences: a) indexes. you need to keep that in mind as every child index is incremented and it can lead to not that obvious bugs; b) constraints. again you can forget about that view and loose bunch of time playing with constraints in code not understanding why they behave that way
            – NDQuattro
            Nov 18 at 21:21






          • 2




            Maybe the better way is to extend a ConstarintLayout and override onViewAdded and onViewRemoved to set visibility=View.GONE itself if it has 0 children? Since you are using ConstarintLayout as root view, constraints on GONE views still should work
            – Andrey Busik
            Nov 18 at 21:58











          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',
          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%2f53363229%2fstop-empty-constraintlayout-from-maximum-stretching%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








          up vote
          0
          down vote













          I was unable to find a proper solution.





          The simplest workaround I came up with is to add an extra view with height=0 and never remove it:



          <?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">

          <android.support.constraint.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@android:color/holo_red_dark"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent">

          <FrameLayout
          android:id="@+id/somethingWithNoHeight"
          android:layout_width="match_parent"
          android:layout_height="0dp" />

          <!--<TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Lorem ipsum" />-->
          </android.support.constraint.ConstraintLayout>
          </android.support.constraint.ConstraintLayout>


          I believe you should fill a bug to be sure that developers know about such a problem






          share|improve this answer

















          • 1




            I also went that way though I see here two inconveniences: a) indexes. you need to keep that in mind as every child index is incremented and it can lead to not that obvious bugs; b) constraints. again you can forget about that view and loose bunch of time playing with constraints in code not understanding why they behave that way
            – NDQuattro
            Nov 18 at 21:21






          • 2




            Maybe the better way is to extend a ConstarintLayout and override onViewAdded and onViewRemoved to set visibility=View.GONE itself if it has 0 children? Since you are using ConstarintLayout as root view, constraints on GONE views still should work
            – Andrey Busik
            Nov 18 at 21:58















          up vote
          0
          down vote













          I was unable to find a proper solution.





          The simplest workaround I came up with is to add an extra view with height=0 and never remove it:



          <?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">

          <android.support.constraint.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@android:color/holo_red_dark"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent">

          <FrameLayout
          android:id="@+id/somethingWithNoHeight"
          android:layout_width="match_parent"
          android:layout_height="0dp" />

          <!--<TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Lorem ipsum" />-->
          </android.support.constraint.ConstraintLayout>
          </android.support.constraint.ConstraintLayout>


          I believe you should fill a bug to be sure that developers know about such a problem






          share|improve this answer

















          • 1




            I also went that way though I see here two inconveniences: a) indexes. you need to keep that in mind as every child index is incremented and it can lead to not that obvious bugs; b) constraints. again you can forget about that view and loose bunch of time playing with constraints in code not understanding why they behave that way
            – NDQuattro
            Nov 18 at 21:21






          • 2




            Maybe the better way is to extend a ConstarintLayout and override onViewAdded and onViewRemoved to set visibility=View.GONE itself if it has 0 children? Since you are using ConstarintLayout as root view, constraints on GONE views still should work
            – Andrey Busik
            Nov 18 at 21:58













          up vote
          0
          down vote










          up vote
          0
          down vote









          I was unable to find a proper solution.





          The simplest workaround I came up with is to add an extra view with height=0 and never remove it:



          <?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">

          <android.support.constraint.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@android:color/holo_red_dark"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent">

          <FrameLayout
          android:id="@+id/somethingWithNoHeight"
          android:layout_width="match_parent"
          android:layout_height="0dp" />

          <!--<TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Lorem ipsum" />-->
          </android.support.constraint.ConstraintLayout>
          </android.support.constraint.ConstraintLayout>


          I believe you should fill a bug to be sure that developers know about such a problem






          share|improve this answer












          I was unable to find a proper solution.





          The simplest workaround I came up with is to add an extra view with height=0 and never remove it:



          <?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">

          <android.support.constraint.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@android:color/holo_red_dark"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent">

          <FrameLayout
          android:id="@+id/somethingWithNoHeight"
          android:layout_width="match_parent"
          android:layout_height="0dp" />

          <!--<TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Lorem ipsum" />-->
          </android.support.constraint.ConstraintLayout>
          </android.support.constraint.ConstraintLayout>


          I believe you should fill a bug to be sure that developers know about such a problem







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 18 at 20:20









          Andrey Busik

          15611




          15611








          • 1




            I also went that way though I see here two inconveniences: a) indexes. you need to keep that in mind as every child index is incremented and it can lead to not that obvious bugs; b) constraints. again you can forget about that view and loose bunch of time playing with constraints in code not understanding why they behave that way
            – NDQuattro
            Nov 18 at 21:21






          • 2




            Maybe the better way is to extend a ConstarintLayout and override onViewAdded and onViewRemoved to set visibility=View.GONE itself if it has 0 children? Since you are using ConstarintLayout as root view, constraints on GONE views still should work
            – Andrey Busik
            Nov 18 at 21:58














          • 1




            I also went that way though I see here two inconveniences: a) indexes. you need to keep that in mind as every child index is incremented and it can lead to not that obvious bugs; b) constraints. again you can forget about that view and loose bunch of time playing with constraints in code not understanding why they behave that way
            – NDQuattro
            Nov 18 at 21:21






          • 2




            Maybe the better way is to extend a ConstarintLayout and override onViewAdded and onViewRemoved to set visibility=View.GONE itself if it has 0 children? Since you are using ConstarintLayout as root view, constraints on GONE views still should work
            – Andrey Busik
            Nov 18 at 21:58








          1




          1




          I also went that way though I see here two inconveniences: a) indexes. you need to keep that in mind as every child index is incremented and it can lead to not that obvious bugs; b) constraints. again you can forget about that view and loose bunch of time playing with constraints in code not understanding why they behave that way
          – NDQuattro
          Nov 18 at 21:21




          I also went that way though I see here two inconveniences: a) indexes. you need to keep that in mind as every child index is incremented and it can lead to not that obvious bugs; b) constraints. again you can forget about that view and loose bunch of time playing with constraints in code not understanding why they behave that way
          – NDQuattro
          Nov 18 at 21:21




          2




          2




          Maybe the better way is to extend a ConstarintLayout and override onViewAdded and onViewRemoved to set visibility=View.GONE itself if it has 0 children? Since you are using ConstarintLayout as root view, constraints on GONE views still should work
          – Andrey Busik
          Nov 18 at 21:58




          Maybe the better way is to extend a ConstarintLayout and override onViewAdded and onViewRemoved to set visibility=View.GONE itself if it has 0 children? Since you are using ConstarintLayout as root view, constraints on GONE views still should work
          – Andrey Busik
          Nov 18 at 21:58


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53363229%2fstop-empty-constraintlayout-from-maximum-stretching%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

          Ottavio Pratesi

          Tricia Helfer

          15 giugno