How to create sticky headers in RecyclerView like the picture attached? - android

I want to implement the title set at the top like the picture above and please be aware that I am using recyclerview like below. Can anyone have any idea?
<NestedScrollView>
<TextView/>
<RecyclerView/>
<TextView/>
<RecyclerView/>
</NestedScrollView>

To Achieve this, you have to pin your title text view. once the image is scrolled over this, then unpin your title. I suggest you, to use Sectioned RecyclerView Library.
With Nested Recycler View & Item Decorator also you can develop like this.

Related

Add views dynamically in ScrollView without ListView

I'm creating an android app.There is an activity that shows application settings and user profile.So I create xml file like this.
<RelativeLayout>
<ScrollView>
<LinearLayout>
<LinearLayout>
//Layout for user profile
</LinearLayout>
<ListView>
//for application setting
</ListView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
But ,as I read, nested ListView inside ScrollView is not good. "User Profile layout" is different from "Setting Layout". And there are many items inside "Setting ListView".So I must scroll both "profile layout" and "Settings " in order to get the bottom. I want to add settings(string and icon) programmatically. Are there some ways to achieve this?
Sorry for my bad English writing skill.
What you are looking for is RecyclerView adapter with different view holders for profile layout and settings layout.
For your reference enter link description here
You have to create/bind profile layout for position 0 and application setting layout for all the other positions in the RecyclerView Adapter.

How can i achieve a viewpager for a certain portion of my screen?

I want to achieve a horizontal scroll view for a linear layout. I thought of doing this using viewpager but i am not able to figure out how?
Layout I want to achieve:
You need to take 2 FrameLayouts inside your parent linear layout and inside of the frame layout add your view pager. Something like below,
<FrameLayout>
<ViewPager/>
</FrameLayout>
<FrameLayout>
<ViewPager/>
</FrameLayout>
</LinearLayout>

Recyclerview items invisible/ Missing when keyboard is visible

Problem :
My recyclerview item have one edittext.
If user edit the edittext -> Keyboard will appear & some list items missing. (means recyclerview shrink when keyboard open after keyboard close shrinked recyclerview not expanded)
My xml design
<ScrollView>
<ConstraintLayout>
<other views>
<recyclerview/>
</ConstraintLayout>
</ScrollView>
Manifest activity windowSoftInputMode
android:windowSoftInputMode="adjustPan"
Tried lot of google & SO. But no luck. Anyone give me solution. If anyone need more info let me know. I will give more details.
UPDATE:
My xml code - https://pastebin.com/diz4t9mp
My issue - Video reference
https://drive.google.com/file/d/15J4hOnCM7Gu6uvklhzlSSD7XUCmmGmzg/view?usp=sharing
Change this
<ScrollView>
<ConstraintLayout>
<other views>
<recyclerview/>
</ConstraintLayout>
</ScrollView>
to
<android.support.v4.widget.NestedScrollView>
<ConstraintLayout>
<other views>
<recyclerview/>
</ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
NestedScrollView is used when there is a need for a scrolling view
inside another scrolling view. Normally this would be difficult to
accomplish since the system would be unable to decide which view to
scroll , it supports acting as both a nested scrolling parent and child on both new and old versions of Android.

What type of View is used?

I have been trying to figured out what kind of View was the 2 rectangle, I would like to use the same kind of design. I though at first it was a CardView but I think it can be since they are not the same.
Sorry if my question is really basic, I'm still on the learning process.
This view is not one single view, but rather a compound view. To reproduce this type of view, I would recommend, broadly, something like this:
<LinearLayout>
<CardView>
<TextView/> //Name
<TextView/> //Location w/ drawableStart set
<TextView/> //Phone w/ drawableStart set
<TextView/> //link w/ drawableStart set
</CardView>
<CardView>
<TextView/> //Title
<TextView/> //Body
</CardView>
</LinearLayout>
Both of them are CardView only, give a light gray background for the root layout and for card views give elevation and corner radius.

CardView with RecyclerView/ListView in ScrollView

tl;dr: How to achieve the layout shown in the screenshot below? Placing ListView to a ScrollView is apparently not recommended, but is there actually any other way to achieve it?
The whole question: I want to have multiple CardViews in my app, and one (or more) of them will have either RecyclerView or ListView in it (it doesn't really matter to me which one of those). The whole view is supposed to be scrollable - not only the ListViews in their parent CardViews. I basically need to achieve similar layout as the Play Store app has.
The first option I tried was this (the code is obviously simplified):
<LinearLayout android:orientation="vertical">
<CardView>
<!-- Some content of the first card. -->
</CardView>
<CardView>
<ListView/>
</CardView>
</LinearLayout>
The result was not what I wanted, the ListView was only scrollable in its parent CardView but the whole view wasn't scrollable like it is in the Play Store app. So now I wrapped it all in a ScrollView:
<ScrollView
android:fillViewport="true"
android:isScrollContainer="true">
<LinearLayout orientation="vertical">
<CardView>
<!-- Some content of the first card. -->
</CardView>
<CardView>
<ListView/>
</CardView>
</LinearLayout>
</ScrollView>
And I programmatically set the height of the bottom card to fit the ListView's height (number of elements in the ListView * height of one list item element). Now the whole view is scrollable, and the bottom card's height is the same as the height of the ListView, so the ListView isn't scrollable inside the CardView which is exactly what I wanted.
Now the actual problem: I got it working as described above, but I know this particular issue (ListView in a ScrollView) has been asked about many times before and the answer has always been the same - don't put neither RecyclerView nor ListView in a ScrollView because it causes performance problems. Well, so what's the correct approach then? How did Google do it in the Play Store app? I tried decompiling the Play Store app with APKTool but there weren't any layout files (maybe I did something wrong). Is my approach correct? My ListView will only display a few items (I guess it will be at most 20 items) - will it cause some performance issues in this case?
I wouldn't ask about this if all the answers wouldn't always mention that we shouldn't put ListView in a ScrollView. Is there any other way how to achieve the layout described by the screenshot above?
The first thing to address is why you're "not supposed to" use wrap_content on a ListView or a RecyclerView and put it in a scrollable container: it defeats the entire view-recycling purpose of these components.
What makes a ListView or RecyclerView better than a LinearLayout inside a ScrollView is that the system only needs to create enough views to display everying that fits inside the visible area. When you "scroll" the visible area, the views that disappear off one end can be re-used for the views that scroll into view from the other end. When you make your list/recycler wrap_content, this recycling is impossible, so you might as well just manually add your views to a LinearLayout instead.
That being said, RecyclerView does support using wrap_content... it just means you won't get view recycling. If this performance hit doesn't cause you problems, there's no objectively evil code here.
The only way to know for sure if the performance penalty is problematic or not is to just try it, test it, measure it, and decide for yourself. With 20 items, I suspect you have nothing to worry about.
The next thing to think about is the fact that Google has tons of resources and manpower and can afford to be extremely clever. Perhaps the Play Store app is as you say, with some sort of scrollable parent container that holds cards, each of which have some sort of adapter view within. But it's equally possible that they're doing something completely different, like using a single RecyclerView and "faking" the appearance of cards by using an ItemDecoration. Or perhaps they are using some sort of custom view subclass that the public doesn't have access to.
As for how you could recreate something similar, I suspect a hierarchy like this will work just fine:
<NestedScrollView>
<LinearLayout>
<CardView>
<RecyclerView/>
</CardView>
<CardView>
<RecyclerView/>
</CardView>
<CardView>
<RecyclerView/>
</CardView>
</LinearLayout>
</NestedScrollView>
I would recommend you to use Sectioned RecyclerView for this purpose. Every single item layout would have a cardView in it instead of creating a cardView as a parent.
Refer to this library: https://github.com/luizgrp/SectionedRecyclerViewAdapter

Categories

Resources