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" />
Related
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 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.
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.
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/carousal_parent_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
and in Inner FrameLayout i am adding a Horizontal Recyclerview with fixed Size .
carousel_parent_layout = findViewById(R.id.carousal_parent_layout);
carouselPager = view.findViewById(R.id.carouselPager);
carouselPagerAdapter = new CarouselPagerAdapter(mContext, carouselData, carouselPager);
carouselPager.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
carouselPager.setHasFixedSize(true);
carousel_parent_layout.addView(carouselPager);
But on touching Recyclerview it is not flinging . I have tried with SnapHelper and android:descendantFocusability="blocksDescendants" but nothing is working. Any help is highly appreciated. Thanks a lot in advance for reading the question.
I need both horizontal scrolling and vertical scrolling. how can be it possible using recycler views, or should i use 2 way views? Any one help me please.
How will set the adapter for the same?
you can add recycler view to your layout file
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/recycler_view"
xmlns:android="http://schemas.android.com/apk/res/android" />
In java file set its orientation to horizontal or vertical
LinearLayoutManager LayoutManager = new LinearLayoutManager(this);
LayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);// or LinearLayoutManager.VERTICAL
RecyclerView.setLayoutManager(LayoutManager);
You have to use two times same adapter one for HORIZONTAL and second for VERTICAL.
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/recycler_view"
xmlns:android="http://schemas.android.com/apk/res/android" />
Use above in XML file two times one for HORIZONTAL and one for VERTICAL
This for HORIZONTAL
LinearLayoutManager LayoutManager = new LinearLayoutManager(this);
LayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
RecyclerView.setLayoutManager(LayoutManager);
OrderedDetailsAdapter orderedDetailsAdapter;
orderedDetailsAdapter = new OrderedDetailsAdapter(OrderDetailsActivity.this, orderDetailsPojo.getOrderItemsList());mOrderDetailsRecyclerView.setAdapter(orderedDetailsAdapter);
This for VERTICAL
LinearLayoutManager LayoutManager = new LinearLayoutManager(this);
LayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
RecyclerView.setLayoutManager(LayoutManager);
OrderedDetailsAdapter orderedDetailsAdapter;
orderedDetailsAdapter = new OrderedDetailsAdapter(OrderDetailsActivity.this, orderDetailsPojo.getOrderItemsList());mOrderDetailsRecyclerView.setAdapter(orderedDetailsAdapter);
Just add your Vertical-LinearLayout recyclerView inside HorizontalScrollView :
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/nested"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</HorizontalScrollView>
For vertical recyclerview add these lines:
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(linearLayoutManager);