I made a recycler view with linear layout manager to display items.
This is my RecyclerView.
<com.example.Recycler.RecyclerView
android:id="#+id/recycler1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
And this is the item layout that I'm using for RecyclerView.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:id="#+id/content"/>
</LinearLayout>
Everything works well, but I've got a small issue. The data which I fill the recycler with are 10 items.
The recycler in some devices displays the 10 items, in other devices, it displays only 3 items and make scrollbars to show the rest.
I tried to use android:scrollbars="none" in the recycler, but it made the recycler show only 3 items.
I tried also to use setNestedScrollingEnabled(false); but it didn't work either.
Any help?
You should make height for RecyclerView to match_parent.
Here is the code should be:
<com.example.Recycler.RecyclerView
android:id="#+id/recycler1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Use RecyclerView android.support.v7.widget.RecyclerView instead of your custom com.example.Recycler.RecyclerView
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler1"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
The RecyclerView widget is a part of the v7 Support Libraries. To use this widget in your project, add below Gradle dependency to your app's module:
dependencies {
...
compile 'com.android.support:recyclerview-v7:25.0.+'
}
Related
I am using two RecyclerView in LinearLayout in NestedScrollView see xml file.
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvData1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvData2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
And i wrote the code animation in onBindViewHolder Adapter class
holder.parentView.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.right_to_left));
And My all code is perfect when i deleted code NestedScrollView then animation is perfect working and NestedScrollView visible then it is not working animation like simple to display all items in row of adapter.
Android guys share your best experience what you did.
Thank You !
Change your coding style, can you make nested recyclerview, I mean, In
one recyclerview put rest of recyclerview. you can create this kind of
recyclerview by using VIEW_TYPE
I'm facing a tricky situation here and I don't know how to solve this problem.
In my project I have a custom BottomSheetDialogFragment and in the layout a FrameLayout to add or replace Fragments.
Now I have a Fragment and inside I have a RecyclerView with the height:="wrap_content" because I want the BottomSheetDialogFragment only use the necessary space. Everything looks great, the problem appear when I put another view inside of the same layout and set the RecyclerView bellow or above of that view.
The RecyclerView ignores the size of the other view (or views) and always grows to the max screen size, and then it's no possible to see a few elements and even scroll.
I saw a solution, some developers are suggesting to add paddingBottom equals to the height of the view. But in my case doesn't works because I want to have a dynamic solution.
Above I'll share a few images of the problem and GitHub Repository with a sample.
Thanks for your attention!
I've manage to do what you need just need to use this as your fragment_sample.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/rclItems"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<Button
android:id="#+id/btnAddMoreItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rclItems"
android:text="#string/add_1_item"/>
</LinearLayout>
Explanation
Using a LinearLayout gives you the ability to work with weight, and the vertical orientation allows you to place an item below the other. The weight on the recyclerview will increase the height of it as needed until filling the screen. The next item you add would be added to the recyclerview but you'll need to scroll the list to see it
The android developers blog says that :-
The scrolling containers in your bottom sheet must support nested scrolling .
Try changing your fragment_sample.xml as below to make the recyclerview scroll working and to make the add button persistent.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:id="#+id/next"
android:layout_above="#id/btnAddMoreItems"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/rclItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v4.widget.NestedScrollView>
<Button
android:id="#+id/btnAddMoreItems"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:text="#string/add_1_item"/>
</RelativeLayout>
Note: making bottomsheet layout a child view of CoordinatorLayout will allow you to get the implement BottomSheetBehavior and recieve its transitions callbacks .
Here's my layout.
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_marginBottom="45dp"
android:layout_height="wrap_content">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true">
<Button
android:layout_width="300dp"
android:layout_height="100dp"
android:id="#+id/noob_button"
android:text="haha" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/noob_button"
android:orientation="vertical"
android:clipToPadding="false"
android:scrollbars="vertical" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
This is all inside RelativeLayout.
I have set recyclerview.setNestedScrol..(false);
It still hangs and if I set fixed height of the RecyclerView it doesn't hang. It scrolls but the scroll is not smooth.
You do not actually need a RecyclerView inside a NestedScrollView. As far as I have understood your question, you need a Button and a RecyclerView under the button. So you might consider adding the Button as the header of the RecyclerView which is neater implementation.
If you are thinking of adding a header in your RecyclerView please see my answer here on how this can be achieved.
I have explained how a footer can be added. The same rule applies for adding a header view as well. Please let me know if you have any further questions regarding this.
I want to implement two RecyclerView with different layout in single activity. The above RecyclerView should scroll vertical and the one below should scroll horizontal. But when I run the app, only either one RecyclerView is displayed. If first view is displayed then it works properly and scrolls vertical, while second RecyclerView is missing. And if second one is displayed then it scrolls vertical when it should do horizontal scroll and the first RecyclerView is missing.
Here is what i want. Source: Github,CardView-Recyclerview-Picasso
Here is my layout
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBackgroundLight"
android:smoothScrollbar="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/CategoriesRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/videoRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="130dp"
android:layout_below="#+id/CategoriesRecyclerView"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
You may directly use the 2 Recycler Views without NestedScrollView.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/CategoriesRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/videoRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="130dp"
android:layout_below="#+id/CategoriesRecyclerView"/>
</RelativeLayout>
And in your CategoriesRecyclerView whose height is wrap_content, use setAutoMeasureEnabled(true) on the Layout manager used for the recyler view.
If you want to scroll the horizontal scrollview full upside on page scroll then use scrollview otherwise you can do without scrollview. Also to achieve your layout just give the horizontal recyclerview fixed height and then you can see both recyclerview .
I have a horizontal RecyclerView inside a ListView, and i need to catch the event onItemClickListener from the Listview. I'm targeting API15, and i tested on a emulator with Nougut also in my device Android Version 4.4.2.
the following code its the custom layout for the Listview.
<?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"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="#drawable/ic_prueba"
android:gravity="center"
android:id="#+id/tv_column_1"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/recycler_view_item"/>
</LinearLayout>
When the application runs on my device, the event onItemClickListener from the listview works only over the textview. Over the recycler view items, i can't get the listview event.
This is mock Data on the list view
The RecyclerViews are probably eating the events.
Set clicklisteners on the individual views in the Recyclerviews.
Also you should probably use a RecyclerView instead of the ListView.