Recyclerview : ImageView in CardView fits center and hides other textviews before scrolling
up vote
0
down vote
favorite
I'm trying to present a CardView with 3 textviews and a imageView inside a RecyclerView. Problem is that if before you start scrolling imageView is filled completely in cardview and the textviews are hidden even though the relative layout inside the cardview is supposed to keep the image on the left side. After scrolling some of the cardviews will end up looking how i want them to, if i sort the List and update the adapter all the cardviews except the last work like i want them to.
Here's the relevant XML's:
Cardview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:padding="4dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cv"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="1dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_photo"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="1dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_name"
android:layout_toEndOf="@+id/cv_photo"
android:layout_alignParentTop="true"
android:textSize="14sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_number"
android:layout_toEndOf="@+id/cv_photo"
android:layout_below="@+id/cv_name"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_date"
android:layout_toEndOf="@+id/cv_photo"
android:layout_below="@+id/cv_number"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
RecyclerView:
<android.support.v7.widget.RecyclerView
android:id="@+id/ProfileRecycler"
android:layout_width="368dp"
android:layout_height="491dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_below="@+id/viewbox"
android:clipToPadding="false"
/>
Adapter code (has everything that's necessary)
@Override
public ProfileViewHolder onCreateViewHolder(ViewGroup viewGroup, int i){
View view = LayoutInflater.from(segruppe.getContext()).inflate(R.layout.profileview,viewGroup,false);
ProfileViewHolder holder = new ProfileViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(ProfileViewHolder ProfileViewHolder,int i){
profileViewHolder.name.setText(profiles.get(i).getName());
profileViewHolder.number.setText(String.valueOf(profiles.get(i).getNumber()));
profileViewHolder.dato.setText(profiles.get(i).getDate().toString());
if(profiles.get(i).getImage()!=null)
Glide.with(context).load(profiles.get(i).getImage()).into(profileViewHolder.image);
}
Fragment code for creating the cardview recycler:
profileRecycler = getView().findViewById(R.id.ProfileRecycler);
profileAdapter = new ProfileAdapter(getContext(),profileList);
GridLayoutManager glm = new GridLayoutManager(getActivity(),4, LinearLayoutManager.HORIZONTAL,false);
profileRecycler.setLayoutManager(glm);
profileRecycler.setAdapter(profileAdapter);
Can anyone see what is going wrong here? (Might be worth mentioning that if there's no imageView in the cardview then it remains completely static during and after scrolling like it's supposed to)
android layout android-recyclerview
add a comment |
up vote
0
down vote
favorite
I'm trying to present a CardView with 3 textviews and a imageView inside a RecyclerView. Problem is that if before you start scrolling imageView is filled completely in cardview and the textviews are hidden even though the relative layout inside the cardview is supposed to keep the image on the left side. After scrolling some of the cardviews will end up looking how i want them to, if i sort the List and update the adapter all the cardviews except the last work like i want them to.
Here's the relevant XML's:
Cardview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:padding="4dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cv"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="1dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_photo"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="1dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_name"
android:layout_toEndOf="@+id/cv_photo"
android:layout_alignParentTop="true"
android:textSize="14sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_number"
android:layout_toEndOf="@+id/cv_photo"
android:layout_below="@+id/cv_name"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_date"
android:layout_toEndOf="@+id/cv_photo"
android:layout_below="@+id/cv_number"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
RecyclerView:
<android.support.v7.widget.RecyclerView
android:id="@+id/ProfileRecycler"
android:layout_width="368dp"
android:layout_height="491dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_below="@+id/viewbox"
android:clipToPadding="false"
/>
Adapter code (has everything that's necessary)
@Override
public ProfileViewHolder onCreateViewHolder(ViewGroup viewGroup, int i){
View view = LayoutInflater.from(segruppe.getContext()).inflate(R.layout.profileview,viewGroup,false);
ProfileViewHolder holder = new ProfileViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(ProfileViewHolder ProfileViewHolder,int i){
profileViewHolder.name.setText(profiles.get(i).getName());
profileViewHolder.number.setText(String.valueOf(profiles.get(i).getNumber()));
profileViewHolder.dato.setText(profiles.get(i).getDate().toString());
if(profiles.get(i).getImage()!=null)
Glide.with(context).load(profiles.get(i).getImage()).into(profileViewHolder.image);
}
Fragment code for creating the cardview recycler:
profileRecycler = getView().findViewById(R.id.ProfileRecycler);
profileAdapter = new ProfileAdapter(getContext(),profileList);
GridLayoutManager glm = new GridLayoutManager(getActivity(),4, LinearLayoutManager.HORIZONTAL,false);
profileRecycler.setLayoutManager(glm);
profileRecycler.setAdapter(profileAdapter);
Can anyone see what is going wrong here? (Might be worth mentioning that if there's no imageView in the cardview then it remains completely static during and after scrolling like it's supposed to)
android layout android-recyclerview
Change the hight of your cardview layout toandroid:layout_height="wrap_content"
– Nilesh Rathod
Nov 20 at 5:59
try giving fix height and width to the imageview
– Kevin Kurien
Nov 20 at 6:00
ChangeLinearLayout
height towrap_content
of list item.
– Piyush
Nov 20 at 6:02
thanks giving a fixed height to the imageview was enough :)
– Flash fernando
Nov 20 at 6:05
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to present a CardView with 3 textviews and a imageView inside a RecyclerView. Problem is that if before you start scrolling imageView is filled completely in cardview and the textviews are hidden even though the relative layout inside the cardview is supposed to keep the image on the left side. After scrolling some of the cardviews will end up looking how i want them to, if i sort the List and update the adapter all the cardviews except the last work like i want them to.
Here's the relevant XML's:
Cardview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:padding="4dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cv"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="1dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_photo"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="1dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_name"
android:layout_toEndOf="@+id/cv_photo"
android:layout_alignParentTop="true"
android:textSize="14sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_number"
android:layout_toEndOf="@+id/cv_photo"
android:layout_below="@+id/cv_name"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_date"
android:layout_toEndOf="@+id/cv_photo"
android:layout_below="@+id/cv_number"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
RecyclerView:
<android.support.v7.widget.RecyclerView
android:id="@+id/ProfileRecycler"
android:layout_width="368dp"
android:layout_height="491dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_below="@+id/viewbox"
android:clipToPadding="false"
/>
Adapter code (has everything that's necessary)
@Override
public ProfileViewHolder onCreateViewHolder(ViewGroup viewGroup, int i){
View view = LayoutInflater.from(segruppe.getContext()).inflate(R.layout.profileview,viewGroup,false);
ProfileViewHolder holder = new ProfileViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(ProfileViewHolder ProfileViewHolder,int i){
profileViewHolder.name.setText(profiles.get(i).getName());
profileViewHolder.number.setText(String.valueOf(profiles.get(i).getNumber()));
profileViewHolder.dato.setText(profiles.get(i).getDate().toString());
if(profiles.get(i).getImage()!=null)
Glide.with(context).load(profiles.get(i).getImage()).into(profileViewHolder.image);
}
Fragment code for creating the cardview recycler:
profileRecycler = getView().findViewById(R.id.ProfileRecycler);
profileAdapter = new ProfileAdapter(getContext(),profileList);
GridLayoutManager glm = new GridLayoutManager(getActivity(),4, LinearLayoutManager.HORIZONTAL,false);
profileRecycler.setLayoutManager(glm);
profileRecycler.setAdapter(profileAdapter);
Can anyone see what is going wrong here? (Might be worth mentioning that if there's no imageView in the cardview then it remains completely static during and after scrolling like it's supposed to)
android layout android-recyclerview
I'm trying to present a CardView with 3 textviews and a imageView inside a RecyclerView. Problem is that if before you start scrolling imageView is filled completely in cardview and the textviews are hidden even though the relative layout inside the cardview is supposed to keep the image on the left side. After scrolling some of the cardviews will end up looking how i want them to, if i sort the List and update the adapter all the cardviews except the last work like i want them to.
Here's the relevant XML's:
Cardview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:padding="4dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cv"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="1dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_photo"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="1dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_name"
android:layout_toEndOf="@+id/cv_photo"
android:layout_alignParentTop="true"
android:textSize="14sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_number"
android:layout_toEndOf="@+id/cv_photo"
android:layout_below="@+id/cv_name"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cv_date"
android:layout_toEndOf="@+id/cv_photo"
android:layout_below="@+id/cv_number"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
RecyclerView:
<android.support.v7.widget.RecyclerView
android:id="@+id/ProfileRecycler"
android:layout_width="368dp"
android:layout_height="491dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_below="@+id/viewbox"
android:clipToPadding="false"
/>
Adapter code (has everything that's necessary)
@Override
public ProfileViewHolder onCreateViewHolder(ViewGroup viewGroup, int i){
View view = LayoutInflater.from(segruppe.getContext()).inflate(R.layout.profileview,viewGroup,false);
ProfileViewHolder holder = new ProfileViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(ProfileViewHolder ProfileViewHolder,int i){
profileViewHolder.name.setText(profiles.get(i).getName());
profileViewHolder.number.setText(String.valueOf(profiles.get(i).getNumber()));
profileViewHolder.dato.setText(profiles.get(i).getDate().toString());
if(profiles.get(i).getImage()!=null)
Glide.with(context).load(profiles.get(i).getImage()).into(profileViewHolder.image);
}
Fragment code for creating the cardview recycler:
profileRecycler = getView().findViewById(R.id.ProfileRecycler);
profileAdapter = new ProfileAdapter(getContext(),profileList);
GridLayoutManager glm = new GridLayoutManager(getActivity(),4, LinearLayoutManager.HORIZONTAL,false);
profileRecycler.setLayoutManager(glm);
profileRecycler.setAdapter(profileAdapter);
Can anyone see what is going wrong here? (Might be worth mentioning that if there's no imageView in the cardview then it remains completely static during and after scrolling like it's supposed to)
android layout android-recyclerview
android layout android-recyclerview
edited Nov 20 at 10:33
Athira
324115
324115
asked Nov 20 at 5:57
Flash fernando
33
33
Change the hight of your cardview layout toandroid:layout_height="wrap_content"
– Nilesh Rathod
Nov 20 at 5:59
try giving fix height and width to the imageview
– Kevin Kurien
Nov 20 at 6:00
ChangeLinearLayout
height towrap_content
of list item.
– Piyush
Nov 20 at 6:02
thanks giving a fixed height to the imageview was enough :)
– Flash fernando
Nov 20 at 6:05
add a comment |
Change the hight of your cardview layout toandroid:layout_height="wrap_content"
– Nilesh Rathod
Nov 20 at 5:59
try giving fix height and width to the imageview
– Kevin Kurien
Nov 20 at 6:00
ChangeLinearLayout
height towrap_content
of list item.
– Piyush
Nov 20 at 6:02
thanks giving a fixed height to the imageview was enough :)
– Flash fernando
Nov 20 at 6:05
Change the hight of your cardview layout to
android:layout_height="wrap_content"
– Nilesh Rathod
Nov 20 at 5:59
Change the hight of your cardview layout to
android:layout_height="wrap_content"
– Nilesh Rathod
Nov 20 at 5:59
try giving fix height and width to the imageview
– Kevin Kurien
Nov 20 at 6:00
try giving fix height and width to the imageview
– Kevin Kurien
Nov 20 at 6:00
Change
LinearLayout
height to wrap_content
of list item.– Piyush
Nov 20 at 6:02
Change
LinearLayout
height to wrap_content
of list item.– Piyush
Nov 20 at 6:02
thanks giving a fixed height to the imageview was enough :)
– Flash fernando
Nov 20 at 6:05
thanks giving a fixed height to the imageview was enough :)
– Flash fernando
Nov 20 at 6:05
add a comment |
active
oldest
votes
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
});
}
});
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%2f53387062%2frecyclerview-imageview-in-cardview-fits-center-and-hides-other-textviews-befor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53387062%2frecyclerview-imageview-in-cardview-fits-center-and-hides-other-textviews-befor%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
Change the hight of your cardview layout to
android:layout_height="wrap_content"
– Nilesh Rathod
Nov 20 at 5:59
try giving fix height and width to the imageview
– Kevin Kurien
Nov 20 at 6:00
Change
LinearLayout
height towrap_content
of list item.– Piyush
Nov 20 at 6:02
thanks giving a fixed height to the imageview was enough :)
– Flash fernando
Nov 20 at 6:05