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?
Related
I have a recyclerview set up with a linear layout at horizontal where each imageview takes up the full width of the visible recyclerview. I was wondering how to fix this such that the imageview items are next to each other the way you'd see this in a carousel. A copy of what I'm seeing is found below. Thanks!
In your layout item, which you are inflating using the adapter class.. you should define the width of the layout as either wrap_content or a fixed value(for eg: 200dp or something else according to your need). I think you have used match_parent that's why you are facing such an issue.
Feel free to ask if something is unclear.
Looks like the ImageView has been resized based on the layout_height specified and you have a value of wrap_content on the layout_width. You should set the ImageView's attribute android:adjustViewBounds to true.
Reference: https://developer.android.com/reference/android/widget/ImageView#attr_android:adjustViewBounds
I have a VerticalGridView in which i plan to use multiple VerticalGridViews.
Wrap_Content does nothing for a VerticalGridView if its set on it's height, The GridLayoutManager simply ignores it if the view is in a normal view, and it does match_parent it seems. If it is in another Vertical Scrolling view the height is 0.
I cannot override the GridLayoutManager without duplicating the entire leanback library.
How can I achieve wrap_content for it?
setColumnWidth method can be used to achieve it:
gridView.setColumnWidth (ViewGroup.LayoutParams.WRAP_CONTENT)
In my case I extend VerticalGridView and call this method in constructor to make WRAP_CONTENT default behavior
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.
I have created a gridView layout with a RecyclerView and have also created the necessary adapter class to populate its cells with imageViews.However, i can't figure out how to make the imageViews larger or set a custom length and width for them.In a previous project, i was using LayoutParams directly on the imageViews like this:
imageView.setLayoutParams(new GridView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
But that doesn't seem to work here.Any ideas?
If anyone is interested, i solved it by implementing the solution to this question : match_parent width does not work in RecyclerView.
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>