I want to use the horizontal scroll recycler.
For this, I use LinearLayoutManager (LinearLayoutManager.HORIZONTAL), this works, but different indentation is obtained for the items.
Screenshot - https://i.stack.imgur.com/Mqp8A.png
Layout for fragment:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/list_related"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="20dp"
android:paddingBottom="20dp"
tools:listitem="#layout/item_2_lenta"/>
</LinearLayout>
Layout for item:
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
app:cardBackgroundColor="#ff0">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
UPD
Creating a layoutManager
vRelatedStub.setOnInflateListener((viewStub, sView) -> {
vLabelRelated = sView.findViewById(R.id.label_related);
vListRelated = sView.findViewById(R.id.list_related);
vLoaderRelated = createLoaderView(sView, mAdapterRelated);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext(),
LinearLayoutManager.HORIZONTAL, false);
vListRelated.setLayoutManager(layoutManager);
vListRelated.setAdapter(mAdapterRelated);
});
vRelatedStub.inflate();
Found an error in my code.
The thing was that I asked margin to the first item in the bind holdar,
this remained from the vertical linear manager.
Related
I have two RecyclerView, both have a vertical orientation, I need to scroll one of them so that the second scrolls, that is, their scrolling is synchronous, I thought that it is possible to apply one LinearLayoutManager to these two RecyclerView and then it will be work, but in this log, the error LinearLayoutManager is already attached to a RecyclerView will be generated, so I don't know how to be, help me find a solution, I need two independent RecyclerView with different adapters, but which scroll synchronously, so do not write about GridLayoutManager, thanks.
xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:clipToPadding="false"
android:orientation="vertical"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:clipToPadding="false"
android:orientation="vertical"/>
</LinearLayout>
Cod
val RLM_0 = LinearLayoutManager(context)
rv_0.setHasFixedSize(false)
rv_0.isNestedScrollingEnabled = false
rv_0.layoutManager = RLM_0
adapter_0 = Adapter_0(itemTasks, requireActivity())
rv_0.adapter = adapter_0
val RLM_1 = LinearLayoutManager(context)
rv_1.setHasFixedSize(false)
rv_1.isNestedScrollingEnabled = false
rv_1.layoutManager = RLM_1
adapter_1 = Adapter_1(itemTasks, requireActivity())
rv_1.adapter = adapter_1
Solution 1:
Check is: Sync scrolling of multiple RecyclerViews
Solution 2:
There is an other way to do so, the idea is to disable scroll for each recycler view and surround them with a scroll view.
This is how you can implement it:
binding.recyclerViewOne.setOnTouchListener((v, event) -> true);
binding.recyclerViewTwo.setOnTouchListener((v, event) -> true);
And for the layout:
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>
</ScrollView>
I have a RecyclerView and inside I have a RecyclerView. and child RecyclerView is no scrolling I try put a child RecyclerView inside a scrollView NeastedCrollView but it doesn't work :
No I have this parent recyclerView:
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/vehicle_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="#dimen/text_dp_20"
android:paddingTop="10dp"
android:scrollbars="none"
tools:ignore="MissingConstraints" />
and this is a child list :
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom|center_horizontal"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="100dp"
android:scrollbars="none" />
</androidx.core.widget.NestedScrollView>
First of all, don't use NestedScrollView, RecyclerView handles everything about scrolling!
use the below links guidelines for improving and optimizing your RecyclerViews, here some useful references:
https://www.geeksforgeeks.org/how-to-create-a-nested-recyclerview-in-android/
https://android.jlelse.eu/easily-adding-nested-recycler-view-in-android-a7e9f7f04047
follow one of them step by step!
you're first need in one recylerView in main activity
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
2-and in MainActivity.java :
LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this);
ItemAdapter itemAdapter = new ItemAdapter(buildItemList());
rvItem.setAdapter(itemAdapter);
rvItem.setLayoutManager(layoutManager);
3- recyclerView in Layout Adapter:
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_sub_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
4- in Adapter :
LinearLayoutManager layoutManager = new LinearLayoutManager(
itemViewHolder.rvSubItem.getContext(),
LinearLayoutManager.VERTICAL,
false
);
layoutManager.setInitialPrefetchItemCount(item.getSubItemList().size());
// Create sub item view adapter
SubItemAdapter subItemAdapter = new SubItemAdapter(item.getSubItemList());
itemViewHolder.rvSubItem.setLayoutManager(layoutManager);
itemViewHolder.rvSubItem.setAdapter(subItemAdapter);
itemViewHolder.rvSubItem.setRecycledViewPool(viewPool);
the end.
you see full code in link
I'm trying to make a horizontal recyclerview in my Android application so I see a of tutorials to make it, its very complicated because I don't want to add images or on click listeners I just have a card and textView inside it and I want to add an id to every single item I have some background about that below
This is my activity of recyclerview items:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="43dp"
app:cardBackgroundColor="#000"
app:cardCornerRadius="20dp"
app:cardElevation="10dp">
<TextView
android:id="#+id/horizontal_data_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="Test"
android:textColor="#38ef7d"
android:textSize="20sp"
android:textStyle="bold"
android:paddingStart="18dp"
android:paddingEnd="18dp"
tools:ignore="HardcodedText"/>
</androidx.cardview.widget.CardView>
</RelativeLayout>
And I created a class named RecyclerViewAdapter.
I will add this RecyclerView to a named activity called SettingsActivity.java
Any ideas?
Assuming you use LinearLayoutManager in your RecyclerView, then you can pass true as to third argument in the LinearLayoutManager constructor.
For example:
mRecyclerView.setLayoutManager(
LinearLayoutManager(
this,
LinearLayoutManager.HORIZONTAL,
true
)
)
change RelativeLayout width and height
android:layout_width="wrap_content"
android:layout_height="wrap_content"
and Remove this line android:orientation="vertical"
and
mRecyclerView.setLayoutManager(
LinearLayoutManager(
this,
LinearLayoutManager.HORIZONTAL,
true
)
)
For horizontal scrolling in recycler view set the layout manager for recyclerview as:
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false));
Hope this should help.
I'm developing an app that displays popular movies right now. It uses TMDB API to fetch this data. I'm using RecyclerView which displays clickable ImageViews in a grid consisting 2 columns.
This is the result I want to achieve:
an edge to edge grid of all movies that I can only achieve by hard coding values:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">`
<ImageView
android:layout_width="185dp" <!--HARDCODED VALUES-->
android:layout_height="278dp"<!--HARDCODED VALUES-->
android:contentDescription="#string/movie"
android:id="#+id/rv_image_view" />
</LinearLayout>
If I use layout_width="match_parent" or layout_height="wrap_content" I get extremely weird and skewed results. Like this one. How should I fix this?
Please don't mark this as duplicate. I've searched far and wide for this and came up with absolutely nothing.
try this create a layout file like this
<?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="wrap_content"
android:orientation="vertical"
>
<ImageView
android:id="#+id/movies_item"
android:layout_width="185dp"
android:layout_height="278dp"
android:scaleType="fitXY"/>
</LinearLayout>
In activity :
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getApplicationContext(), 2);
recyclerView.setLayoutManager(layoutManager);
<?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="wrap_content"
android:orientation="vertical"
android:layout_margin="1dp">
<ImageView
android:scaleType="fitXY"
android:id="#+id/movies_item"
android:layout_width="match_parent"
android:layout_height="180dp"/>
</LinearLayout>
I want to display the selected item as well as the previous and the next in a RecyclerView as I show in the image.
Here's what I need:
Any help is appreciated.
This is mi XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_operations"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
When you setting LayoutManager to your RecyclerView force it to have Horizontal layout:
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view);
myList.setLayoutManager(layoutManager);
try the following code snippet:
yourRecyclerView.setLayoutManager(new LinearLayoutManager(yourContext, LinearLayoutManager.HORIZONTAL, false));
I suggest you to use Fancy Cover Flow
<at.technikum.mti.fancycoverflow.FancyCoverFlow
android:layout_width="match_parent"
android:layout_height="match_parent"
fcf:maxRotation="45"
fcf:unselectedAlpha="0.3"
fcf:unselectedSaturation="0.0"
fcf:unselectedScale="0.4" />