i add basically some properties to recyclerview to set reverse such as this code:
<android.support.v7.widget.RecyclerView
android:id="#+id/messagesView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="LinearLayoutManager"
app:reverseLayout="true"
app:stackFromEnd="true"/>
what i try to do? i'm trying to show last item in recyclerview without scroll to last position, in pasted code i have first item in start and i have to scroll to last position programmatically
how can i change this xml layout to have this ability?
You haven't posted any Java code. So try this:
Set this LayoutManager to the RecyclerView.
recyclerView.setLayoutManager(new LinearLayoutManager(context, VERTICAL, true));
Did you try to set the attributes from code? According to this question, that seems to work.
mLayoutManager = new LinearLayoutManager(getActivity());
mLayoutManager.setReverseLayout(true);
mLayoutManager.setStackFromEnd(true);
Its worked for me , Moves the focus on Last item of the RecyclerView.
mRecyclerView.getLayoutManager().smoothScrollToPosition(mRecyclerView,null, finalCustomItems.size()-1);
or,
mPagerAdapter.highlightPosition(listView.getAdapter().getItemCount() - 1);
Related
So I've spent the last few hours trying to create a horizontal scrolling Recyclerview.
I'm pretty sure that I'm following the correct techniques for setting the LayoutManager for the Recyclerview, but it just won't work. on the preview it works, but once I push it to the Emulator, it still renders the list in vertical mode instead of horizontal.
I haven't made any references/changes to the Recyclerview programmatically (I tried setting the LayoutManager before, but it also didn't work).
Screenshot showing the issue:
try adding this code to your java class in the onCreate Method
mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));//set your recyclerview layout to hoizontal
also try posting your java or kotlin code next time to get better feedback.
You should call Layoutmanager from fragment/activity. If you are using Kotlin, do this
XML
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Fragment/Activity
val layout = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
recycler.layoutManager = layout
*Change this with requireContext() if in fragment
I have a RecyclerView setup like that:
<androidx.recyclerview.widget.RecyclerView
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarThumbVertical="#android:color/transparent"
app:fastScrollEnabled="true"
app:fastScrollHorizontalThumbDrawable="#drawable/thumb_drawable"
app:fastScrollHorizontalTrackDrawable="#drawable/line_drawable"
app:fastScrollVerticalThumbDrawable="#drawable/thumb_drawable"
app:fastScrollVerticalTrackDrawable="#drawable/line_drawable"/>
// Linear layout manager
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
// Touch helper for scrolling
ItemTouchHelper touchHelper = new ItemTouchHelper(touchHelperCallback);
touchHelper.attachToRecyclerView(recyclerView);
// Simple adapter
MyAdapter adapter = new MyAdapter(myDataset);
recyclerView.setAdapter(adapter);
Every item has a circle that, if long pressed, changes the visualization to only allow other items to be selected.
Sporadically, and this is why I can't understand what's going wrong, the long pressed items get an overlapped duplicated "dead" item without ViewModel data that is stuck on the view. If that item gets scrolled off screen (I suppose when it's recycled) it disappears and everything seems ok. You can see it in the next animation.
This is so annoying and I've tried everything but can't track it down. Any idea?
EDIT: New hint, it happens starting from Android 9!
I have n items in a list. i.e Item1 ,Item2,Item3..Item-n. I want to open them on the click of a button and make them visible in a horizontal manner. For Example
ITEM1 ITEM2 ITEM3......ITEM-N
How to draw the same in xml design in android.
Please help to solve the same.
Use like it
xml layout
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
Use in Activity class:
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView_home_10);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
// If using recylerview in srollview
recyclerView.setNestedScrollingEnabled(false);
// set Adapter
recyclerView.setAdapter(adapter);
LayoutManager is the class that layout views in RecyclerView. So change recyclerView.setLayoutManager(LayoutManager) if you want to change layout. In your case, if you use LinearLayoutManager, do this by calling:
LinearLayoutManager layoutManager = ...
recyclerView.setLayoutManager(layoutManager);
//when you want horizontal
layoutManager.setOrientation(context,LinearLayoutManager.HORIZONTAL,false);
//when you want vertical
layoutManager.setOrientation(context,LinearLayoutManager.VERTICAL,false);
RecyclerView is shown with vertical orientation, and can not set this property, because orientation belongs to the LinearLayoutManager object. Any way to simulate HORIZONTAL layout?
Anyway the linearLayoutManager created in code is set to HORIZONTAL.
llm.setOrientation(LinearLayoutManager.HORIZONTAL);
try to add these parameters to your RecyclerView inside your layout xml:
android:orientation="horizontal"
android:scrollbars="horizontal"
app:layoutManager="LinearLayoutManager"
RecyclerView won't show your actual data in the Editor Layout as the data you add in your RecyclerView is added Dynamically in your java code through Adapter and you implement a layout manager for your recyclerView in your java code and your Editor Layout displays the elements that are in your xml, so in your XML file its just a plain recyclerView which has no idea of what data is added in your Java implementation or what LayoutManager is to be implemented on it.
AFAIK, there is no such facility editor provide yet.
although you can set the orientation of LinearLayoutManager Horizontal at runtime, this will fulfill your requirement.
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
I search answer for me, but didn't find work answer for me. I got strange error in viewing my items in RecycleView:
I use different view's for RecycleView.
I try use this code:
mLayoutManager.setAutoMeasureEnabled(true); // false doesn't work too
But it doesn't help me.
UPD 1 I forgot note this, sorry. When I start app, I have no errors (items like Normal on image) but when I started scroll my RecycleView I got problem)
UPD 2 I return back to the compile 'com.android.support:recyclerview-v7:23.1.1', but it doesn't help me (. So I add code and xml with mey RecycleView and I hope you help me.
XML:
<android.support.v7.widget.RecyclerView
android:id="#+id/dashboard_recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="none" />
And code:
mRecyclerView = (RecyclerView) parent.findViewById(R.id.dashboard_recycle_view);
mLayoutManager = new LinearLayoutManager(getContext());
mLayoutManager.setAutoMeasureEnabled(false);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setHasFixedSize(false);
mRecyclerView.setAdapter(mRecycleAdapter);
Set wrap_content for the recyclerview and for your viewholder layout parent.
This worked for me.
Set wrap_content instead of match_parent ( if you set as match_parent ) as that causes the layout to match the parent giving you the large spaces.
I encountered the same problem. If you only change RecyclerView to wrap_content, the startup page looks fine but you will get blank space after swiping up.
Solution:
In addition to change android:layout_height of RecyclerView to wrap_content, you should also go to the layout XML file where your RecyclerView items are, and modify the surrounding RelativeLayout's android:layout_height attribute to wrap_content.
Please refer to this thread.