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.
Related
I am trying to have a leanback VerticalGridView. Inside it I would like to have multmple VerticalGridView. The thing is that wrap_content is ignored by the layoutManager so that the grid height is only the height of one single item insted showing all of them.
I tried to set the layoutManager to a LinearLayoutManager(contenxt, VERTICAL, false) but problem still there. Also I have tried xml obvious options.
Any idea?
I am following a tutorial on grid layout. In particular, I am replicating Suragch's answer.
The code itself is working fine, except I would like to center the RecyclerView in the activity.
I've tried
android:gravity="center"
and
android:layout_gravity="center"
on both the RelativeLayout AND RecyclerView, but neither works.
Also, I would like to eliminate the gaps between each column. Does anyone know how to go about doing this?
Try android:layout_centerInParent=true into <RecyclerView>
Depending on your parent Layout
If its RelativeLayout then
android:layout_centerHorizontal=true in RecyclerView
if its LinearLayout then
android:layout_gravity=center_horizontal in RecyclerView
One more interesting thing you can do in Adapter
the main parent Layout in adapter
try doing this
android:gravity=center_horizontal in main layout of adapter
As the title says. I'm trying to display extremely complex layout with a full height of the viewport but I need it scrollable because under it there is a simple recyclerview with some items. I already thought about putting everything inside a multi type recyclerview adapter but the logic of the upper layout is so complex that I don't think it's possible.
I tried using NestedScrollView with fillViewport set to true but I'm stuck defining dimensions of this upper layout and recyclerview below it. Everything needs to be inside one layout because scrollview can't have more than one child, but when I put everything in a linearlayout and set the upper layout to match_parent it's showing fullscreen until data loads in the recyclerview below it. Then it's treating this upper layout as if it was wrap_content.
I'm out of ideas how can I do something like this. Preferably best would be to have some sort of ViewGroup which would support scrolling and resize the recyclerview below it as we scroll, but I'm not sure how to do it.
you need to set the layout to something like this:
<NestedScrollView - height:match_parent>
<LinearLayout - height:wrap_content>
<LinearLayout(topview) - height:wrap_content/>
<RecyclerView - height:wrap_content />
</LinearLayout>
</NestedScrollView>
And then you programmatically change the height of the "topview" to equal nestedscrollview.
This is a short question:
Suppose I have a RecyclerView that has undefined number of items, what should I do to it, so that if there is a small number of items that (all) can fit the screen, they will be centered and the user won't be able to scroll ?
Of course, if there are too many items, that cannot fit the screen, I would like to have the RecyclerView to show them all as normal (from the beginning to how much it can show, and allow to scroll).
To understand what I mean, I think such a thing is possible when using ScrollView (or HorizontalScrollView if in horizontal), together with a LinearLayout that sets the gravity to be centered .
OK, I think I've found a way:
first, we wait for the RecyclerView to finish its layout process, as I've found about here .
Then, you need to check which child views are shown (available in the LayoutManager that you use), and look at the first and last ones.
If both of them are exactly the same as those that of the total items, it means all needed views are shown, so I can add margins on both sides of the RecyclerView (or padding on its container), according to the space that's left.
I found one complicate way to achieve that.
Main concept: set the height of RV dynamicly in code
RecyclerView rv= (RecyclerView) findViewById(R.id.rv);
rv.setAdapter(new MySlideUpAdapter());
rv.setLayoutManager(new LinearLayoutManager(this));
ViewGroup.LayoutParams layoutParams = rv.getLayoutParams();
layoutParams.height=100;
rv.setLayoutParams(layoutParams);
You may need to calculate the RV's height by childcount*childheight to get pricise value. And don't forget to compare the height to the Parent Layout height, make sure RV's height is less than its Parent Layout height.
Here is my Layout
<RelativeLayout...>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv"
android:layout_centerInParent="true"
android:layout_width="match_parent"
<-height will be changed in code, ignore the 50dp->
android:layout_height="50dp">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
When I use a RelativeLayout with either fill_parent or wrap_content as height and an element which specifies: android:layout_alignParentBottom="true" it is ignored and it is aligned at the top. Setting the height of the RelativeLayout to an explicit value makes it work. Any clues?
This seems to be a bug in Android itself, see http://code.google.com/p/android/issues/detail?id=1394.
I worked around it by wrapping my RelativeLayout in a FrameLayout and putting my bottom aligned view as a children of the FrameLayout with android:layout_gravity="bottom". This hinders you from referencing it from within the RelativeLayout so you'll have to work around that (for example using margins).
If anyone has a better workaround, please share.
When you inflate the layout, use inflate(R.layout.whatever, parent, false), where parent is the ListView. If you don't do that (e.g., you pass null for the parent), RelativeLayout gets strange in list rows.
My hack for this andriod bug:
ViewGroup.LayoutParams lp=(ViewGroup.LayoutParams)view.getLayoutParams();
lp.height=view.getContentHeight();//hack for android bug about ViewGroup.LayoutParams.WRAP_CONTENT and android:layout_alignParentBottom="true" on landscape orientation
view.requestLayout();
act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
I was able to get the proper alignment by specifying the problematic TextView with:
android:id="#+id/must_be_bottom_left"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_below="#id/xxx"
where xxx was the id of a TextView that has android:layout_below="#id/yyy"
and yyy is a TextView that is always above both xxx and must_be_bottom_left.
The contents of my list items can vary so that sometimes the "xxx" TextView is View.GONE, but even then the layout works as expected.
I don't know how fragile or merely seredipidous this work-around is. I am using Android 1.6 and I haven't tested it for forward compatability.