A view or Layout like GridView - java

I am trying to create a custom view like a GridView but with the difference of scroll bar functionality. i.e. I want that the GridView should create the column and rows dynamically and must hold a TextView or EditText view inside each cell of the grid and the custom view can be scrolled in vertically and horizontally too.
I have been tried with Table and default Grid Layout but I failed. Any idea, suggestion or comments are welcome.
Thank you.

You should use RecyclerView for this purpose. You will have to declare the number of Columns upfront. You cannot have different number of columns at runtime.
However Horizontal and Vertical Scrolling at the same time is tricky but still can be done.
Checkout: http://belladunovska.com/tech/nested-recycler-view-in-android
There is a talk on the same topic by Android Lead of NewCircle Training
Also you can checkout TwoWayView: https://github.com/lucasr/twoway-view (I think it is not using RecyclerView)

Related

how to show mutiple image in grid like facebook and linked in

I need to show multiple image in grid like example given here.
and also need plus icon while images is more than some certain counts
There are multiple ways to implement it
Two horizontal/vertical LinearLayout
TableLayout with two rows
ConstraintLayout which its children are chained together
GridView
RecyclerView with GridLayoutManager
and more ... :D
Possibly you want to fetch the images dynamically, and there are several collection views: RecyclerView, ListView etc. RecyclerView is common since you can modify the layout(for your case, columns) with various LayoutManagers. Since you haven't provide any code, I cannot help you with that, but here is a guide that might be helpful.
For the plus icon mechanism, you can modify your RecyclerViewAdapter code, limiting the count(in getItemCount()) to a certain number and visible a transculent foreground with '+number' in the ViewHolder code for the last item.

RecyclerView with unknown/variable row layouts

Since RecyclerView uses ViewHolders, it means that you must have a predefined layout for each row. But what if each row needs to have a variable amount of views displayed?
For example, say I'm creating an instant messaging application where users can attach pictures to messages. They could attach anywhere from 0 to x pictures. When you create a RecyclerView to display these pictures (that are downloaded from a server), how would you make the rows include the correct number of ImageViews to display them?
There's a few ways I can think of doing this, but none really seem like good options.
Create ImageViews in onBindViewHolder, add them to a layout in the ViewHolder. (Isn't this what the ViewHolder tries to prevent? This would probably be laggy, especially with lots of pictures)
Restrict the amount of pictures the user can attach to a message to x, then add x ImageViews to the layout that are set to invisible/gone. In onBindViewHolder, set the ImageViews to display the picture and set these ImageViews visible. (What if I allow pictures & videos to be attached? Do I then need to add x ImageViews and x VideoViews as well?)
Put a GridView in each RecyclerView item and populate the GridView
inside onBindViewHolder. (I assume this would have no benefit over
option #1 because it's pretty much the same thing?)
That's all I can think of. Is there any other option that is designed for this sort of situation that I have not come across? Or what are the typical approaches taken towards this problem?
You need to create a heterogenous RecyclerView which will display multiple different ViewHolders. There are several ways to accomplish this.
The basic approach is that based on the number of photos/videos associated with each item in your RecyclerView.Adapter you would override getItemViewType(int position) (a method which is part of the RecyclerView.Adapter class) to return a different int. This int is the viewType parameter passed into createViewHolder(ViewGroup parent, int viewType). You would then use the correct ViewHolder/layout based on the viewType argument.
See here for a good tutorial.
If you don't mind using a library for an alternate approach I recommend AdapterDelegates.

How to remove a view from a LinearLayout without affecting the positions of the other children?

I am trying to add/remove views to a LinearLayout inside a ScrollView. I would like to remove/add views to the LinearLayout while it is scrolling for larger lists might blow memory and/or be slow. Is there any way to remove a View from the LinearLayout without it affecting the position of its siblings?
When I call linearLayout.removeChildAt(0), all of the views snap back one, making it really difficult to maintain a constant scrolling effect.
I am not sure if this is applicable for you(maybe u are aware of this already), but usually when there is a list of view which you have to show, instead of using scrollviews and adding/removing subviews yourself, you can make use of ListView in android.
When you remove a view, replace it with a blank placeholder view of the same size as the removed view.
By adding/subtracting the size of the removed View at position 0 to the parents padding, I effectively stopped the "chopping" effect when I was removing views.

iPhone has UITableView, what does android have

I have an app on the iPhone that is completely table view driven. On android all I see is a static table, how can I create a table that I can populate with data that I requested from the network.
You could use either ListView or GridView. ListView has a method getView which you override to customize ListView item. This very much like (UITableViewCell *)tableView... in iphone, except that you needn't count the height of each cell. If you want to have something like tableView with sections you could use ExpandableListView. Here are links to Android ListView, Android Expandable ListView and Android GridView. There can also be found very useful examples in Android Dev web-site.
You can use GridView or ListView with custom View for row. In both cases you can supply a BaseAdaper (or a subclass of it) through which you can manipulate the data.
If you want the exact grid border like example here you go Android Grid Border... Obviously you can render data dynamically from whatever the source is...

horizontal pager with vertical pager. How can we apply?

If any one has answer for this question please comment me.
Vertical-Pager
Horizontal-Pager
So please check this two projects. I just want to implement both in only one class so I can scroll both side with only one class.
I know for a fact that the Horizontal Pager class supports Vertical scrolling, so I believe you can nest them. Add code to the Horizontal Paging class that can detect Vertical Paging.
Or,
you could add a ScrollView to every child from the ViewGroup inside the Horizontal Pager.

Categories

Resources