RecyclerView LinearLayout always appearing on top of other elements
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
add a comment |
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
post your full activity_messages.xml file code
– Saurabh Bhandari
Jan 2 at 5:31
add a comment |
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
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
java android android-recyclerview android-linearlayout
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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 supportmatch_parent
, so we use0dp
(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.
That fixed it. Thanks for the clarification for usingmatch_parent
insideConstraintLayout
. Didn't know about that.
– Bert Hanz
Jan 2 at 5:56
add a comment |
it is just Constrain issue.
You haven't set constraint for recyclerview try to add constrain and run again
it will work
add a comment |
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)
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 supportmatch_parent
, so we use0dp
(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.
That fixed it. Thanks for the clarification for usingmatch_parent
insideConstraintLayout
. Didn't know about that.
– Bert Hanz
Jan 2 at 5:56
add a comment |
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 supportmatch_parent
, so we use0dp
(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.
That fixed it. Thanks for the clarification for usingmatch_parent
insideConstraintLayout
. Didn't know about that.
– Bert Hanz
Jan 2 at 5:56
add a comment |
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 supportmatch_parent
, so we use0dp
(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.
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 supportmatch_parent
, so we use0dp
(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.
answered Jan 2 at 5:41
Ben P.Ben P.
24.7k32250
24.7k32250
That fixed it. Thanks for the clarification for usingmatch_parent
insideConstraintLayout
. Didn't know about that.
– Bert Hanz
Jan 2 at 5:56
add a comment |
That fixed it. Thanks for the clarification for usingmatch_parent
insideConstraintLayout
. 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
add a comment |
it is just Constrain issue.
You haven't set constraint for recyclerview try to add constrain and run again
it will work
add a comment |
it is just Constrain issue.
You haven't set constraint for recyclerview try to add constrain and run again
it will work
add a comment |
it is just Constrain issue.
You haven't set constraint for recyclerview try to add constrain and run again
it will work
it is just Constrain issue.
You haven't set constraint for recyclerview try to add constrain and run again
it will work
answered Jan 2 at 5:01
Rohit ChauhanRohit Chauhan
587417
587417
add a comment |
add a comment |
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)
add a comment |
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)
add a comment |
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)
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)
answered Jan 2 at 5:32
SnortSnort
243
243
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
post your full activity_messages.xml file code
– Saurabh Bhandari
Jan 2 at 5:31