For an App I'm developing, I have an ImageView on Top of a ListView in a RelativeLayout. What I want is for the ImageView to scroll with the ListView. So if the ListView items move up, the ImageView should move up just as much. Any ideas on how to do this?
for that you should set header to listview
mListView.addHeaderView(mImageView);
You can add your imageview as a header to listview.
listview.addHeaderView(ImageView);
The image will scroll along with listview.
public void addHeaderView (View v)
Added in API level 1 Add a fixed view to appear at the top of the
list. If addHeaderView is called more than once, the views will appear
in the order they were added. Views added using this call can take
focus if they want.
NOTE: Call this before calling setAdapter. This is so ListView can
wrap the supplied cursor with one that will also account for header
and footer views.
Parameters v The view to add.
If you wanna go for adding Header, go for this:
listViewObj.addHeaderView(imgViewobj);
PS: use before listViewObj.setAdapter();
else take a look at this open source project, hope this would help:
Link to emilsjolander/StickyListHeaders
Related
I am developing a comment section for my app. My goal is to create a way for users to reply to other comments and to be able to view and hide this comment list like on instagram:
How can I create a replies list within an item in a RecyclerView? Also, how to show and hide the replies?
Thanks in advance!
You can try with below design
All comments are located inside a RecyclerView.
Each item is a vertical LinearLayout(1) including:
First layer content a TextView (used for comment)
Second layer content another vertical linear layout(2), including:
a text view: View more replies
a second layer is another vertical linear layout(3) again
The third linear layout will contain replies, and will be show/hide on text view "view more replies" clicks. Newly added replies will be add to linear layout 3 by LinearLayout.addView() method.
Refresh recycler view items at resonable time by calling recycler view adapter notifyDataSetChanged() or similar methods.
you can make Expandable Recyclerview with the comment as the parent and the replies as the children
you can check this library and use it or edit on it and use it
https://github.com/thoughtbot/expandable-recycler-view
I want to implement the below image in android ,
I have used Relative Layout to display content and Recycler view to display comments but I want both under one scroll while my problem is recycler view is creating another scroll.
I also thought to add a layout dynamically but in that every layout I have to implement click listener for every child , which is not good for performance
What could be the best way to implement it
You can make a ListView where row contains Comments part and add Image as a Header of that ListView.
The other way is to create a Custom Adapter and include Image and Comments as a single row of a ListView
For implementing a click event on each item you can refer to this answer
Why don't you use a ListView with custom elements in it (that look like the comments on the picture) instead of the RecyclerView
I'm implementing a listview that looks like this :
So basicly I have a listview, with a headerview. My problem is to set the space between the headerview and the rest of the listview. If anyone has a clue, thanks :)
To set a gap below the header view you can just add marginBottom to the header view. That should do it. But like Pauland said, never ever EVER put a listview inside a scrollview. You are basically placing two vertical-scrolling views ontop of each other and Android can't tell which one to scroll when the user swipes!
I want to have a view with the following vertical layout
An image (IamgeView)
A description of the image (TextView)
A list of comments
The constraint is that I want the entire page to scroll and not just the list of comments.
The number of comments may vary. If I use a ListView for the comments the entire screen doesn't scroll.
Please suggest a way to do this.
You can add a header view to your ListView. Whatever you put in the header view will scroll just like the list.
I have an Android project that displays results, using a simple listview. What I need is to display an image at the top of listview as follows:
Please note, the image on top, should be scrollable. Would you please help me. Thanks.
Use ListView.addHeaderView() to add a header view to the top of your ListView.
List view has header and footer options. You can put your scrollable image view in one XML layout, inflate and use that as list view header.
You can get more info if you search for list view header. The quickest one I can get is
Android listview with header and footer buttons