Getting click on empty/whitespace of recyclerview - android

I need to show images in horizontal RecyclerView, and this RecyclerView is inside a row of RecyclerView. Now sometimes I receive 2 or 3 images and sometimes more that can fit in its width. So, i want it to be Scrollable when there are more items then its width and when it lists few items then i want empty area to be clickable as well. How can i achieve this behavior?
The problem i am having is concerned in first row where the area need to be clickable is not in my control.

I know, This is old question. But I was stumbled upon a similar scenario.
Place the recycler view inside card view (card view is actually a frame layout) and set the recycler view width to wrap_content instead of match_parent. and the card view (parent of the recycler) width to match_parent. This will give you the expected result.
The card view is required, if you want to have the elevated cards for wrapping the recycler view. Otherwise any ViewGroup (like LinearLayout,Framelayout) should work.

You'll need to add a custom GridlayoutManager. Check this https://gist.github.com/ArthurSav/5f80e19d9ba6d562fbd5
from Arthur's Answer

Related

Display list without scrolling

I want to display a list without scrolling vertically. if list height greater than the parent list must start from the next column. if column fit to the parent it must scroll horizontally. Image shows what I want. please help me to solve this problem
In that case you can use a constraint layout. But the logic to break the list should be implemented by you when binding the adapter with the data and view. Recycler view will be a good container. I hope this sheds some light.

Align item outside of List with items inside the List

I got the following recycler view, on the view item there are 5 checkboxes. How could I align the checkboxes inside the recycler view items with the TextView dates on the fragment..?
I tried using the same padding, but different dates got different sizes, as well as phones, so it doesnt display a correct alignment on all instances.. Is there a better way? I would appreciate any kind of indication, this is the last problem so I can publish the application.
You can achieve this in a simple way. Take all the textViews of your fragment inside a linear layout group. And keep the layout_weight similar. Thus the textViews will be equidistant.
Similarly, take the checkboxes in a LinearLayout view group. And keep the layout_weight similar. Thus the textViews will be equidistant.
Ps- check the padding and margin of the items, and adjust accordingly.

When we use a scroll view and Recycler view

In a app we have a activity which displays a list of textview let us take a list of numbers 1-9 or more than that.Which view is useful to display textviews either scroll view or Recycler view?
Recyclerview itself has scrollbar implemented in it. It is used when you have a large dataset.
ScrollView is used when you have a limited set of children on your UI and they are fitted out of your screen, so ScrollView is implemented here to scroll your layout to see all the children.

Scroll Images in a scrollview Android

Hello I am relatively new to android developing. What I am trying to do is create a scroll view where I can scroll through multiples images vertically how do I do that? I tried searching for it but I cannot seem to find a solution for it? should I add multiple image view in a scroll view is that possible? if so how?
please help.
Use GridView for that
GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. The grid items are automatically inserted to the layout using a ListAdapter.
Take and try this Example
or
Create the RelativeLayout inside the ScrollView and add multiple imageview inside the Realtive layout..
First of all if you want to scroll through multiples images vertically then you can use the List View OR Grid view in Android.Both scrolls Vertically.If you want to achieve it through scroll View you can do that by using layout weights to your images or assigning fix height to your images i.e you need to do extra efforts.So better to use List View. You can use the below link for the demo of list view : -
http://www.mkyong.com/android/android-listview-example/

Parent view draw child view efficient

For example, top level LinearLayout view has 300 child view. But device screen dimension only show 11 child view once. How android compute how many child views can show once? How a view know that it will be draw?
Edited
In my work, one case like this:
An parent LinearLayout view may be has hundreds child view. In order to better performance , my solution like this:like lazy load.
List list = new ArrayList();//contain entity object that use construct View object
Default load 5 child view.
Parent LinearLayout view last child view is custom Loading View, I have override it`s onDraw() method. If loading View is draw, that means i need get next 5 child view(get next 5 object from list,and create correspond view).
I want to know how android framework handle this case?
Have u used scroll bar inside the top level LinearLayout view and add child view on that layout that's simple...
An parent LinearLayout view may be has hundreds child view. In order
to better performance , my solution like this:like lazy load.
LinearLayout with(possible) hundreds of child views kind of contradicts better performance. I think what you're looking for is a ListView with an endless adapter(a simple google search will show how to implement it, not something that difficult). This adapter will start loading views(with a loading view showing while the new content loads) as soon as you get to the last loaded element.
If you still want to use a LinearLayout:
If you just want to make the LinearLayout fill the content of the screen when it's first laid out you could post a Runnable on one of your views in the onCreate method (if this is where you'll first populate the LinearLayout). In that Runnable find the height of the LinearLayout and compare it with the combined height of its currently present children. If the combined child height is smaller then the LinearLayout height then add more views to compensate.
If the LinearLayout is in a ScrollView and you want to add additional children when the loading view becomes visible then monitor the scrolling of the ScrollView and when the loading view becomes visible add new children. Seeing when the loading view becomes visible would be done by checking how much the user has scrolled compared with the combined height of the currently present children of the LinearLayout.
Initial response:
Your question is a bit ambiguous regarding what you want to know. If you have a specific problem you should start with that.
For example, top level LinearLayout view has 300 child view. But
device screen dimension only show 11 child view once.
Please don't get yourself in a scenario like this. That number of views is to big an will result in poor performance or even the app crashing if you run out of memory(as all those views will be kept in memory).
How android compute how many child views can show once?
Each View and ViewGroup has the onMeasure method to measure itself and its children if available. The LinearLayout will have its onMeasure method called and in this method it will measure its children(with the measure method) giving them some suggestions on how big should they be(the LinearLayout receives some suggestions on how big it should be from its parent). If you want to see how this is done have a look at the source code of the LinearLayout.
How a view know that it will be draw?
I don't understand what you want to know. To draw the view on the screen its onDraw method will be called.

Categories

Resources