RecyclerView vs LinearLayout when displaying very large chunks of text - android

If I have a recycler view that has a few cards and some of the cards are basically a TextView which a huge amount of text e.g. spanning 3 screens essentially as the user scrolls, are all the benefits of a recycler view essentially gone and I could have gone with a LinearLayout?

If I understand you correctly, your RecyclerView has only three items in it
If so, then yes, you are not recycling much. A ConstraintLayout wrapped in a ScrollView probably is easier to maintain over time.

If you put all the large text in one item, yes, you shouldn't use recycler. Second thing, large text rendering is a performance problem. But if you slit your large text into some smaller parts (small enough to fit 3 or 4 parts in a screen) then recycler will do the hard work for you: only render text when user scroll to it.

Related

Image list with text

I want to achieve something similar to the attached image
I was thinking of using TableLayout with 2 columns for each row.
There will be padding in order to be apart of each other. Then I will put white background for the cell. Lastly, I'll just add the ImageView and TextView.
The images and text are dynamically generated. I will get the image URL and display them.
So, are there any better or more efficient way for implementing what I want to achieve? TableLayout doesn't seem to be that efficient.
Your diagram looks pretty much like a grid - for which you can use a GridLayout in Android: https://developer.android.com/reference/android/widget/GridLayout.html
A layout that places its children in a rectangular grid.
The grid is composed of a set of infinitely thin lines that separate the viewing area into cells. Throughout the API, grid lines are referenced by grid indices. A grid with N columns has N + 1 grid indices that run from 0 through N inclusive. Regardless of how GridLayout is configured, grid index 0 is fixed to the leading edge of the container and grid index N is fixed to its trailing edge (after padding is taken into account).
Every one of the items in the grid can be a Cardview (https://developer.android.com/training/material/lists-cards.html) - and that way you will also benefit of a consistent look and feel with Android, without much effort.
Take into account that the cards (every item in the grid) will have the same height, tho: How to make a grid layout of CardViews with variable height?.
If the height of the elements will be variable, you should better take a look to the StaggeredGridLayoutManager: https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html
What you have to do is use a RecyclerView with a GridLayoutManager.
For a full working implementation: https://inducesmile.com/android/android-gridlayoutmanager-with-recyclerview-in-material-design/

Android. Making my object appear anywhere on the screen

If I want a bunch of objects that appear let's say middle, middle right and occupy have the ability to occupy any part of the screen, would I use gridlayout or relative layout and dp to customize the location?
I think I explained it badly. If I used an analogy, it would be like whack a mole with the hole screen. I was thinking of making a large amount of rows and columns in gridlayout or just using dp. Any insight or suggestions?
The thing about gridview is that its entire purpose is scrolling. If you have lots of data and want to scroll through it in a grid, that's the right answer. If you have a fixed amount of data you want to display in a grid, you want something else- a TableLayout likely.

How to design single row of images?

I am trying to build a row of images. I want the number of images to increase based on screen width. For example, in portrait mode there may be 3 images present, but in landscape there would be five.
I have tried using a GridView, but I am having trouble stopping it from being populated after the first row has been filled (it goes to the next row). Is there an alternative view I should be using or is a GridView the right approach?
If you only want 1 row, then use a LinearLayout. If it needs to scroll, embed it in a HorizontalScrollView.
If you aren't scrolling you can then inflate and add each image, depending on available space.
You could make it more complex by creating custom classes, etc.
You can also try the Two-Way GridView (I've used it - it works great)
How to make grid-view horizontally scrollable in android
I have found a suggestion based off of this. Once a max width has been exceeded on the LinearLayout, simply stop adding to it!

How to make GridView scroll Horizontally and Vertically?

I want to represent a DataBase output to a GridView, the deal is that I want this GridView scroll horizontally and vertically. The reason for that is that I may have a table that has a number of columns that will not fit on screen, So Horizontal scrolling is necessary.
Now for vertical scrolling: I may have a big DataBase (with 100 entries and more...) So I do want it to scroll vertically as well and use the View recycling mechanism to populate the GridView (for the Vertical Scrolling, no View recycling is needed for the Horizontal Scrolling).
I have already stumbled on this solution:
https://gist.github.com/codeswimmer/869685
But I have few problems with this:
1. It uses a deprecate Gallary View.
2. I think this changes the vertical scrolling to a horizontal one but doesn't allow both of them.
Is this even possible?
Any direction on this topic would be really appreciated.

recycling views in scroll view

I have an app that show the tv guide for a list of channels. My UI is made from a a lot of custom views with different widths that show the tv programs, all these custom views are added into a horizontal scrollview that is added into a scrollview so my views can be scroll in 2 dimensions left-right and top-down. It all works good until i add add a lot of views and it starts to slow down very much. So i need a way to recycle views like listiew does in a scrollview maybe there is a custom made scrollview that does this, or someone has an idea how to do this, its strange that scrollview isnt backed up by an adapter like gridview and listview.
I did something similar only my Views were not connected as yours but they were all different sizes.
First you need to define if your entire area (not just viewing screen) has definitive or dynamical number of your custom views.
If you have definitive number of views and their positions you should create their position map with list of Rect's (Rect has a good function whether the xy point belongs). Then you define maximum of Views which are visible on your screen. For this to work without constant loading you should have maximum visible views + at least one line of border views of total objects. After all this you should easily have your own positioning system where you load views which are in bounds of your screen + some overhead (purpose of this is that you want your users to have smooth transition while scrolling at least for some length), if you need to load some in same time you unload (read reuse/ do not dispose objects and create them onScroll events) and place them according to your needs.
And if you want to determine which views should be visible you just go through list and ask whether Views Rect intersects with your Rect of area to be loaded.
Hope this image helps a little bit more
I know it sounds a little bit confusing and difficult to implement but you did not asked a simple question :)
Hope this helps and enjoy your work.
A ScrollView that is backed up by an adapter and recycles views is a ListView, with a couple of extra optional features on top.
Maybe you want a HorizontalScrollView that is backed by an adapter? Searching for HorizontalListView will give you a few results, ex: https://github.com/dinocore1/DevsmartLib-Android.

Categories

Resources