Inside my recycler view item layout I want to add something like horizontal recyclerview layout, because I don't know how many ImageViews I need, that's why I can't create them as a static layout. The number of icons depends on server logic. How can achieve something like the picutre below ?
Thank you in advance!
You Need Add Horizontal Recyclerview Inside The Main Recyclerview.
Your First RecyclerView is Verticle list and inside every index create another RecyclerView It's a Horizontal. so you can display n number of Imageview.
You have to create Recyclerview inside the child layout of your main Recyclerview
Something like
Suppose this is the Main Recyclerview
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/mainRecyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:listitem="#layout/item_demo" />
In your child layout, Let's say item_demo you have to add another Recyclerview for the imageView that you want to show in horizontal
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/mainRecyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:listitem="#layout/item_child" />
item_child layout contains the Imageview that will display horizontally
Related
As described in below image. I have one layout above the recycler view and one below. both tags are the linear layout. I face two problems.
because the recycler view has inner scroll therefore if items in recycler view increase, the first linear layout stays at the same place but I am expecting it to scroll up while scrolling items.
When items increase in recycler view the second layout get disappear. how to make the layout scroll when recycler view reaches its last item.
Tried android:nestedScrollingEnabled="false" it disables the scroll effect but shows only a few items in the recycler view.
Require solutions: if somehow I can make the recycler views items static and display all the available contents. so the parent layout decides whether scroll or not. if size increase it will scroll otherwise not.
You can add both LinearLayouts to the RecyclerView as header and footer views. The top answer in this question should give you an idea how to make this: RecyclerView header and footer
If your two LinearLayout have fixed size, you can fix them inside a RelativeLayout and then insert your RecyclerView "in between".
<RelativeLayout>
<LinearLayout alignParentTop="true" height="100dp" id="#+id/topLayout"/>
<LinearLayout alignParentBottom="true" height="100dp" id="#+id/bottomLayout"/>
<RecyclerView height="match_parent" above="#id/bottomLayout" below="#id/topLayout"/>
</RelativeLayout>
Alternatively, if your top container is a LinearLayout, you can play with weights (1 for top LinearLayout, 1 for bottom LinearLayout, 3 for RecyclerView)
<LinearLayout orientation="vertical">
<LinearLayout height="0dp" weight="1"/>
<RecyclerView height="0dp" weight="3"/>
<LinearLayout height="0dp" weight="1"/>
</LinearLayout>
I have added RecyclerView inside my NestedScrollView. Basically I want RecyclerView to scroll with other Views. The problem that I am facing is that for a small set of data, it is working fine, but for a large set of data(200 entries) whenever I launch the activity, it freezes for about about 3-5 seconds and then loads. I removed the NestedScrollView and it is working flawlessly, but it doesn't provide me the behaviour I want.
(For extra info, I am loading the data from SQLite database. There is no problem in scrolling, as it is smooth. The only problem is the activity is freezing for a while)
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<... Some other Views ...>
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
This case of RecyclerView inside NestedScrollView.
RecyclerView is calling onCreateViewHolder() times equal to your data size.
If data has 200 items, it freezes for onCreateViewHolder() to be called 200 times.
The problem as said above is because RecyclerView as a child or subChild in NestedScrollView measures its height as infinitive when you use WRAP_CONTENT or MATCH_PARENT for height of RecyclerView.
one solution that solved this problem for me was setting the RecyclerView Height to a fixed size. you could set height to a dp value, or you could set it to a pixel value matching devices height if your requirements needs a vertical infinitive RecyclerView.
here is a snippet for setting the recyclerView size in kotlin
val params = recyclerView.layoutParams
params.apply {
width = context.resources.displayMetrics.widthPixels
height = context.resources.displayMetrics.heightPixels
}
recyclerView.layoutParams = params
I faced the same problem!
The solution was to change NestedScrollView to SwipeRefreshLayout.
add this for enable/disable ToolBar Scrolling:
ViewCompat.setNestedScrollingEnabled(recyclerView, true);
As said by Nancy , recyclerview.setNestedScrollingEnabled(false); will solve scroll stuck issue. i too faced this type of issue and solved by false the NestedScroll.
I have a RecyclerView and inside it I want to put CardViews. Now I want these CardViews to overlap themselves like inside a Stackview, but i cannot find a solution to let my view look like this.
The result should look like the reminder app from iOS (see the screenshot) or like a deck of cards. The user should be able to scroll through the cardviews and drag them on the position he wants them to have.
Does anyone have an idea how to solve this problem? Or is there any library that could help me to let my view look like this? I have already tried an custom ItemDecoration but only the visible items of the RecyclerView are shifted and so the RecyclerView has a wrong behavior on scrolling.
You can achieve overlapping of items by using negative bottom margins for your item layout. See the documentations for details.
For example:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"/>
</android.support.v7.widget.CardView>
Is it possible to make a space between horizontal Listview items?
I try this for listview.
android:divider="#ffff00" android:dividerHeight="10dp"
It's working fine in listview. but I want add divider between horizontal Listview items. How to rectify this Problem?. Share Your Idea?
Set border around your list items in xml file or add custom view as below:
<View
android:layout_height="match_parent"
android:width="1dp"
android:background="#ffff00"
/>
what do you mean by horizontal list view in Android?
If it is customised list then add a view betwwen two items and set the backgroundcolor for the view.
With all respect to #Mihir Shah, updating his answer to match your requirement.
Set border around your list items in xml file or add custom view as below:
<View
android:layout_height="match_parent"
android:width="1dp"
android:background="#android:color/transparent"
/>
This will provide space you require.
I want to create a ListView and a few other text boxes for filtering the list.
Is there a way to make it happen using one activity (i.e at the same page)?
One more question:
May I modify a ListView directly without creating a ListActivity? and how do I make the ListView in my ListActivity visible? (how do I link it with the xml?).
Yes. ListActivity seems to cause a lot of confusion for people, when all it is, is a regular activity with a ListView as the content, some helper methods, and that's it.
To add your own, create a new layout file and add all the widgets you need like you would any other layout file. Example:
<LinearLayout xmlns:android="http://schemas.android.com/res/apk/android"
android:weightSum="1.0"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/whatever"
android:layout_weight="0" />
<ListView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" />
</LinearLayout>
You certainly can create a layout which contains both a ListView and other controls! Make your Activity have a layout which contains both your ListView and your other controls.
<RelativeLayout>
<ListView android:id="#+id/listy"/>
<Button android:id="#+id/buttony"
android:layout_below="#id/listy"/>
</RelativeLayout>
In your Activity, you'll still need to hook up your data adapter to the ListView and so forth.
Yes, you can have ListView together with some other required views with in the same Activity. The way I would do this is to define an Activity and add ListView (with width and height set to fill_parent) and add a SlidingDrawer which contains all the options required to alter ListView. With this approach, your ListView will take up all the space on screen and offering user to interact freely. However, on the other hand, SlidingDrawer will give give extra space for all the list altering views/options.