Android Custom GridView with Masonry Logic - android

I'm quite new to the world of Android development, and I'm relatively comfortable working with Adapters and GridViews. However, I'm looking to build something a little more advanced with GridViews that seems to be proving quite difficult without using third-party libraries (impossible from what I've read). Even using a third-party library like Etsy StaggeredGridView (https://github.com/etsy/AndroidStaggeredGrid) I can't seem to get it right. The best I can get is having rows that bleed into other rows, Pinterest-style, but what I'd like is something along these lines:
Where every nth cell actually has the width of two cells and offsets the grid.
So what I'd like some direction on is:
How could I accomplish this repeating pattern using a GridView/ Adapter combo?
Or failing that, how could I do this more efficiently than nesting a bunch of LinearLayouts inside a ScrollView and doing some really messy logic?

You can't. GridView has no way of merging columns like that. You can try using a GridLayout or TabletLayout to obtain that look. However neither support an adapter. You're best bet is to look for 3rd party libraries.
If there isn't going to be a lot of scrollable content, I'd go with (Grid/Table)Layout. You may take a small hit with memory consumption but you'll save yourself a lot of time in implementing your own custom solution. Which just may be your only choice if no 3rd party library exists.
One possibility would be to looking into RecycleView. It's a new view coming out with Android L that will also be in the support library. It's basically a more advanced version of a ListView that allows you to build customizable layouts that scroll and recycle their content. From the looks of it, it appears it would allow you to build an easy solution for your case.

Related

What are the alternatives to RecyclerView for a feed

An app includes a feed like Twitter or Instagram.
Tried it with the RecyclerView.
Would Litho (fblitho.com) be a good alternative to make a good feed with text, videos and pictures? Or maby other libraries?
I would suggest learning more about RecyclerView before trying to move onto different libraries. Even if you do end up using another library, it's always good to have a better understanding of what it's being built on top of.
RecyclerView is the best way to handle feeds like you're looking to build. Even with images, or videos.
If you have any specific questions about RecyclerView, you should ask them here. For example, why does RecyclerView not fit your current needs?
I strongly recommend you to take a look at epoxy. As it description says, it is an Android library for building complex screens in a RecyclerView. Models are automatically generated from custom views or databinding layouts via annotation processing.
Wish it can help you.

ListView with a gridView within infinite height

This is one of the implementations that I have the most difficulty in actually finding the best way to solve.
There are a lot of techniques and ways, but the last answers I found did not really seem to me to solve the problem. Another point is that they are usually very old techniques and libraries.
What I want to do is this:
How do I create this ListView with a GridView inside and the screen has infinite height without using ScrollView, so we know that it is not recommended to use ListView within ScrollView.
I am not asking you to develop the code, but rather recommend me the correct architecture that I should use to implement this (ScrollView, ListView, GridView), or memo a library that has new development concepts that can help me.
This question arises because many of the existing responses are too old and have outdated ideas.
I know the question is of a slightly higher level of complexity, but I accept everyone's help.
Thank you very much.
It is very easy to solve this using a RecyclerView.
The documentation is pretty clear and explains all the details necessary for the development of the functionality.
I will leave the necessary documentation links to implement:
RecyclerView
GridLayoutManager
ItemsViewHolder
We know that it is always better to use native components in the development, I recommend, but if you prefer to use a library ready to solve your problem, here are some interesting:
Sticky Headers
recyclerview-stickyheaders
StickyListHeaders

How To Make List Of Fragments In Android Programmatically?

I'm working on an Android application and one of the features is a list of upcoming events. I need to be able to generate a 'card' so to speak for each of these events and place them in to a scroll view. This would be simple if I knew how many there were going to be and could prepopulate an axml file but I must populate the scrollview programmatically based off the parse of an xml file on the web so that the client can keep it updated. I've searched everything I can think and the best I can find is a custom list view which I do not think will provide the results needed. I've uploaded an example of what I'm trying to do to my google drive and linked to it below. I should also mention my background is completely C# and I've only been working with java for the last two weeks or so, so if anyone could provide a working code example I would be most appreciative.
https://drive.google.com/file/d/0B8alYNlu3SuoSEk0bE55cDhXWVE/view?usp=sharing
I think that basically what you need to do is to implement a RecyclerView using a LinearLayoutManager (this would represent basically a list) with CardViews as the items or just regular layouts designed by you, the CardView will just make your life easier if you need the Material Design cards appearance.
You have many different tutorials as how to implement this, as you can see here:
http://www.binpress.com/tutorial/android-l-recyclerview-and-cardview-tutorial/156
You'll see there that it's exactly what you need but with smaller Cards.
Let me know if this helps.

Bad Idea to create HTML content in android app?

I'm creating an app that needs to display a table, with say, 30 columns and 30 rows. I want the user to be able to use swiping to move around the table/spreadsheet. The idea is that probably the entire table will not be visible on the screen, and if it is, it will hardly be readable, so there will have to be some max-columns-on-screen value. Each cell in the table must be capable of being a different color than the rest.
So far, I've looked into TableLayout. This doesn't seem to support different colors or swiping... actually, it does support different colors via .xml, but this isn't changeable at run time, and seems like it would be very messy anyway.
WebView looks to be an option, as I am proficient with HTML/CSS but can't find many resources about creating HTML and CSS content on the fly with android - only loading it; although I can imagine writing a file with the data and then loading it, and deleting the file. Not sure if any of this is good performance wise.
What direction should I head, before I start heading in the wrong direction? :-)
Yes, it is possible (and not difficult) to support different colors and gesture in the tablelayout rows.
I think it is always a wiser choice implementing the native components, once it has a better performance and it has a better layout adjust to different android versions.
Either method can solve the problem, so it's a judgment call based on your goals and requirements.
On the plus side for Android native views:
They are pre-compiled and easier to parse than HTML, so they will load faster, scroll more quickly, and require less memory.
If you intend to write a lot of Android apps you will need to learn them.
If you took this route, a typical approach to draw multiple columns would be a ViewPager with sliding tabs. See for example the Google Play Store app.
It's not the case that coloring native views dynamically is impossible or messy; it's not hard at all but it takes time to learn how, which brings me to the plus side for HTML/webview:
A programmer with expertise in HTML will solve problems faster by just using HTML.
Layouts designed in HTML for an Android web view can be re-used on other platforms.
Again, it's not really hard to load dynamic HTML into a web view. There are a few tricks you will need to learn but that's it.

effective UI design and positioning for android

I've been working for a while on a rather complex Android application, which involves a lot of layouts and almost all of them are quite complex. However, I am taking a very long time since it is so annoying to position the elements of each layout, since they're not positioned like the dialog editor I'm used to in Visual Studio:
Everything in Android is literally relative to other elements and moving one element usually moves a lot of other elements, plus I can't position anything properly unless I guess the position more or less and move the element several times by guessing the margin on a certain direction.
So my question is, is there a more effective way to design UIs quickly and professionally, so that I don't have to design in such a sluggish way (as I believe it is)? I already tried several editors but they all seem to be very similar to Eclipse's. Is there a more effective way at all?
Also a side note, I'm using a RelativeLayout on each of my layouts
Do not compare visual studio with IDE of android. It has some limitations.Try to use android studio which will help you more in UI design. We can do UI perfectly in android. Relative layout is the best to position the views but should use wisely. Atleast please ellaborate what type of design you want to implement. Atleast provide a sample Image of the design which you want to create. Then only I can tell what you need to do.

Categories

Resources