RecyclerView LinearLayout always appearing on top of other elements












0















I have this screen called Messages that displays a list of recent messages to the user. In my activity_messages.xml file I have this bit of code:



<View
android:id="@+id/horizontal_line"
android:layout_width="351dp"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="@android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.47"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/Game_Button"
app:layout_constraintVertical_bias="0.216" />


Basically, this block of code creates a horizontal line. Below that horizontal, I want to display the user's recent messages.



Below that horizontal line block of code, I have this code:



<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="64dp"
tools:layout_editor_absoluteY="168dp">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>


This takes care of displaying the user's recent messages.



Now in my Messages.java file I have this bit of code:



mMessagesLayoutManager = new LinearLayoutManager(Messages.this);
mRecyclerView.setLayoutManager(mMessagesLayoutManager);
mMessagesAdapter = new MessagesAdapter(getDataSetMessages(), Messages.this);
mRecyclerView.setAdapter(mMessagesAdapter);

for(int i = 0; i < 100; i++) {
MessagesObject obj = new MessagesObject(Integer.toString(i));
resultsMessages.add(obj);
}
mMessagesAdapter.notifyDataSetChanged();


This code is for testing purposes, but it works. It shows all the user's messages a linear order and I am able to scroll through them. My only problem is when I run the program, the recent messages don't start below the horizontal line. Some of the messages are above the horizontal line and on top of the other elements. I think the first message jumps to position (0,0).



How do I fix this? I would like my messages to appear the way they are right now, just below the horizontal line.










share|improve this question

























  • post your full activity_messages.xml file code

    – Saurabh Bhandari
    Jan 2 at 5:31
















0















I have this screen called Messages that displays a list of recent messages to the user. In my activity_messages.xml file I have this bit of code:



<View
android:id="@+id/horizontal_line"
android:layout_width="351dp"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="@android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.47"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/Game_Button"
app:layout_constraintVertical_bias="0.216" />


Basically, this block of code creates a horizontal line. Below that horizontal, I want to display the user's recent messages.



Below that horizontal line block of code, I have this code:



<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="64dp"
tools:layout_editor_absoluteY="168dp">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>


This takes care of displaying the user's recent messages.



Now in my Messages.java file I have this bit of code:



mMessagesLayoutManager = new LinearLayoutManager(Messages.this);
mRecyclerView.setLayoutManager(mMessagesLayoutManager);
mMessagesAdapter = new MessagesAdapter(getDataSetMessages(), Messages.this);
mRecyclerView.setAdapter(mMessagesAdapter);

for(int i = 0; i < 100; i++) {
MessagesObject obj = new MessagesObject(Integer.toString(i));
resultsMessages.add(obj);
}
mMessagesAdapter.notifyDataSetChanged();


This code is for testing purposes, but it works. It shows all the user's messages a linear order and I am able to scroll through them. My only problem is when I run the program, the recent messages don't start below the horizontal line. Some of the messages are above the horizontal line and on top of the other elements. I think the first message jumps to position (0,0).



How do I fix this? I would like my messages to appear the way they are right now, just below the horizontal line.










share|improve this question

























  • post your full activity_messages.xml file code

    – Saurabh Bhandari
    Jan 2 at 5:31














0












0








0








I have this screen called Messages that displays a list of recent messages to the user. In my activity_messages.xml file I have this bit of code:



<View
android:id="@+id/horizontal_line"
android:layout_width="351dp"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="@android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.47"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/Game_Button"
app:layout_constraintVertical_bias="0.216" />


Basically, this block of code creates a horizontal line. Below that horizontal, I want to display the user's recent messages.



Below that horizontal line block of code, I have this code:



<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="64dp"
tools:layout_editor_absoluteY="168dp">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>


This takes care of displaying the user's recent messages.



Now in my Messages.java file I have this bit of code:



mMessagesLayoutManager = new LinearLayoutManager(Messages.this);
mRecyclerView.setLayoutManager(mMessagesLayoutManager);
mMessagesAdapter = new MessagesAdapter(getDataSetMessages(), Messages.this);
mRecyclerView.setAdapter(mMessagesAdapter);

for(int i = 0; i < 100; i++) {
MessagesObject obj = new MessagesObject(Integer.toString(i));
resultsMessages.add(obj);
}
mMessagesAdapter.notifyDataSetChanged();


This code is for testing purposes, but it works. It shows all the user's messages a linear order and I am able to scroll through them. My only problem is when I run the program, the recent messages don't start below the horizontal line. Some of the messages are above the horizontal line and on top of the other elements. I think the first message jumps to position (0,0).



How do I fix this? I would like my messages to appear the way they are right now, just below the horizontal line.










share|improve this question
















I have this screen called Messages that displays a list of recent messages to the user. In my activity_messages.xml file I have this bit of code:



<View
android:id="@+id/horizontal_line"
android:layout_width="351dp"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="@android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.47"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/Game_Button"
app:layout_constraintVertical_bias="0.216" />


Basically, this block of code creates a horizontal line. Below that horizontal, I want to display the user's recent messages.



Below that horizontal line block of code, I have this code:



<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="64dp"
tools:layout_editor_absoluteY="168dp">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>


This takes care of displaying the user's recent messages.



Now in my Messages.java file I have this bit of code:



mMessagesLayoutManager = new LinearLayoutManager(Messages.this);
mRecyclerView.setLayoutManager(mMessagesLayoutManager);
mMessagesAdapter = new MessagesAdapter(getDataSetMessages(), Messages.this);
mRecyclerView.setAdapter(mMessagesAdapter);

for(int i = 0; i < 100; i++) {
MessagesObject obj = new MessagesObject(Integer.toString(i));
resultsMessages.add(obj);
}
mMessagesAdapter.notifyDataSetChanged();


This code is for testing purposes, but it works. It shows all the user's messages a linear order and I am able to scroll through them. My only problem is when I run the program, the recent messages don't start below the horizontal line. Some of the messages are above the horizontal line and on top of the other elements. I think the first message jumps to position (0,0).



How do I fix this? I would like my messages to appear the way they are right now, just below the horizontal line.







java android android-recyclerview android-linearlayout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 5:22









ADM

9,094102554




9,094102554










asked Jan 2 at 4:53









Bert HanzBert Hanz

496




496













  • post your full activity_messages.xml file code

    – Saurabh Bhandari
    Jan 2 at 5:31



















  • post your full activity_messages.xml file code

    – Saurabh Bhandari
    Jan 2 at 5:31

















post your full activity_messages.xml file code

– Saurabh Bhandari
Jan 2 at 5:31





post your full activity_messages.xml file code

– Saurabh Bhandari
Jan 2 at 5:31












3 Answers
3






active

oldest

votes


















3














Change this:




<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="64dp"
tools:layout_editor_absoluteY="168dp">



to this instead:



<android.support.v4.widget.NestedScrollView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/horizontal_line"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">


Two major changes going on here:





  • ConstraintLayout doesn't fully support match_parent, so we use 0dp (which means "match constraints") instead.

  • Add constraints for all four sides. The start/end constraints make the view fill the screen horizontally, and the top/bottom constraints make the view fill everything from below the line to the bottom of the screen.






share|improve this answer
























  • That fixed it. Thanks for the clarification for using match_parent inside ConstraintLayout. Didn't know about that.

    – Bert Hanz
    Jan 2 at 5:56



















1














it is just Constrain issue.
You haven't set constraint for recyclerview try to add constrain and run again
it will work






share|improve this answer































    1














    You can either wrap both views the first view and the scrollview in a LinearLayout with android:orientation="vertical", or you can add constraints (if the root view is a 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%2f54001366%2frecyclerview-linearlayout-always-appearing-on-top-of-other-elements%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      Change this:




      <android.support.v4.widget.NestedScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:layout_editor_absoluteX="64dp"
      tools:layout_editor_absoluteY="168dp">



      to this instead:



      <android.support.v4.widget.NestedScrollView
      android:layout_width="0dp"
      android:layout_height="0dp"
      app:layout_constraintTop_toBottomOf="@+id/horizontal_line"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintBottom_toBottomOf="parent">


      Two major changes going on here:





      • ConstraintLayout doesn't fully support match_parent, so we use 0dp (which means "match constraints") instead.

      • Add constraints for all four sides. The start/end constraints make the view fill the screen horizontally, and the top/bottom constraints make the view fill everything from below the line to the bottom of the screen.






      share|improve this answer
























      • That fixed it. Thanks for the clarification for using match_parent inside ConstraintLayout. Didn't know about that.

        – Bert Hanz
        Jan 2 at 5:56
















      3














      Change this:




      <android.support.v4.widget.NestedScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:layout_editor_absoluteX="64dp"
      tools:layout_editor_absoluteY="168dp">



      to this instead:



      <android.support.v4.widget.NestedScrollView
      android:layout_width="0dp"
      android:layout_height="0dp"
      app:layout_constraintTop_toBottomOf="@+id/horizontal_line"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintBottom_toBottomOf="parent">


      Two major changes going on here:





      • ConstraintLayout doesn't fully support match_parent, so we use 0dp (which means "match constraints") instead.

      • Add constraints for all four sides. The start/end constraints make the view fill the screen horizontally, and the top/bottom constraints make the view fill everything from below the line to the bottom of the screen.






      share|improve this answer
























      • That fixed it. Thanks for the clarification for using match_parent inside ConstraintLayout. Didn't know about that.

        – Bert Hanz
        Jan 2 at 5:56














      3












      3








      3







      Change this:




      <android.support.v4.widget.NestedScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:layout_editor_absoluteX="64dp"
      tools:layout_editor_absoluteY="168dp">



      to this instead:



      <android.support.v4.widget.NestedScrollView
      android:layout_width="0dp"
      android:layout_height="0dp"
      app:layout_constraintTop_toBottomOf="@+id/horizontal_line"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintBottom_toBottomOf="parent">


      Two major changes going on here:





      • ConstraintLayout doesn't fully support match_parent, so we use 0dp (which means "match constraints") instead.

      • Add constraints for all four sides. The start/end constraints make the view fill the screen horizontally, and the top/bottom constraints make the view fill everything from below the line to the bottom of the screen.






      share|improve this answer













      Change this:




      <android.support.v4.widget.NestedScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:layout_editor_absoluteX="64dp"
      tools:layout_editor_absoluteY="168dp">



      to this instead:



      <android.support.v4.widget.NestedScrollView
      android:layout_width="0dp"
      android:layout_height="0dp"
      app:layout_constraintTop_toBottomOf="@+id/horizontal_line"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintBottom_toBottomOf="parent">


      Two major changes going on here:





      • ConstraintLayout doesn't fully support match_parent, so we use 0dp (which means "match constraints") instead.

      • Add constraints for all four sides. The start/end constraints make the view fill the screen horizontally, and the top/bottom constraints make the view fill everything from below the line to the bottom of the screen.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jan 2 at 5:41









      Ben P.Ben P.

      24.7k32250




      24.7k32250













      • That fixed it. Thanks for the clarification for using match_parent inside ConstraintLayout. Didn't know about that.

        – Bert Hanz
        Jan 2 at 5:56



















      • That fixed it. Thanks for the clarification for using match_parent inside ConstraintLayout. Didn't know about that.

        – Bert Hanz
        Jan 2 at 5:56

















      That fixed it. Thanks for the clarification for using match_parent inside ConstraintLayout. Didn't know about that.

      – Bert Hanz
      Jan 2 at 5:56





      That fixed it. Thanks for the clarification for using match_parent inside ConstraintLayout. Didn't know about that.

      – Bert Hanz
      Jan 2 at 5:56













      1














      it is just Constrain issue.
      You haven't set constraint for recyclerview try to add constrain and run again
      it will work






      share|improve this answer




























        1














        it is just Constrain issue.
        You haven't set constraint for recyclerview try to add constrain and run again
        it will work






        share|improve this answer


























          1












          1








          1







          it is just Constrain issue.
          You haven't set constraint for recyclerview try to add constrain and run again
          it will work






          share|improve this answer













          it is just Constrain issue.
          You haven't set constraint for recyclerview try to add constrain and run again
          it will work







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 5:01









          Rohit ChauhanRohit Chauhan

          587417




          587417























              1














              You can either wrap both views the first view and the scrollview in a LinearLayout with android:orientation="vertical", or you can add constraints (if the root view is a ConstraintLayout)






              share|improve this answer




























                1














                You can either wrap both views the first view and the scrollview in a LinearLayout with android:orientation="vertical", or you can add constraints (if the root view is a ConstraintLayout)






                share|improve this answer


























                  1












                  1








                  1







                  You can either wrap both views the first view and the scrollview in a LinearLayout with android:orientation="vertical", or you can add constraints (if the root view is a ConstraintLayout)






                  share|improve this answer













                  You can either wrap both views the first view and the scrollview in a LinearLayout with android:orientation="vertical", or you can add constraints (if the root view is a ConstraintLayout)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 2 at 5:32









                  SnortSnort

                  243




                  243






























                      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%2f54001366%2frecyclerview-linearlayout-always-appearing-on-top-of-other-elements%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

                      android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                      SQL update select statement

                      'app-layout' is not a known element: how to share Component with different Modules