Merging multiple views into a custom view - android

I could use some help with merging multiple views into one, like Pinterest has at
I know how to make a reusable custom view, been searching around custom components, compound controls, checked sdk samples and threads like Custom view made of multiple views , but it was never the proper way. I want it to also show 1 view (where i can set the image/texts dynamically) at the hierarchy viewer instead of 5+ child subviews, as that way increases performance aswell. I checked the github acc of Pinterest too without success :)
Can I somehow achieve it, or Im way too off? Thanks!

Try creating a separate layout.xml file containing all of the views you want to have in your custom view. Then in java all you would have to do is make reference to each of those custom views and fill them with your data.

Related

Multiple CardViews in RecyclerView

I would like to have 2 or more different CardViews which are inflated into a single RecyclerView.
For instance, one card with just text and another with text and an image.
At the moment I have functional code which works with the CardViews independently, but I am unsure of how to inflate the two simultaneously.
The code I have is based off of this Tuts+ tutorial.
Please could someone offer a solution or, alternatively, a better way to do it?
CardView is an advanced View widget that allows you to add other Views onto it. Thus, for your situation, simply add another CardView in your layout file the same manner you added the initial CardView.
Hope this helps.

Setting a background resource for many linearlayouts in scrollview causes lag

I am dynamically adding around 150 linearlayouts to a scrollview in a grid-like layout. If I set the background resource to a drawable for each of them using setBackgroundResource(R.drawable.x), the scrollview shows extremely noticeable lag and choppiness, even though the drawable is a simple colour and border.
If I remove the call to setBackgroundResource, the scrollview is smooth again.
Is this expected to happen with so many views containing backgrounds? If so, how would I go about making a grid with custom backgrounds for each cell?
You're going to want to use a list view in your scroll, and you're going to want to use a ListAdapater:
http://developer.android.com/guide/topics/ui/layout/listview.html
http://developer.android.com/reference/android/widget/Adapter.html
Basically what's going on is you're loading a large number of images into memory, and the scroll view by default doesn't do a very good job of managing releasing and inflating these resources.
Using methods similar to the above, with some custom image management, I've managed to get thousands of views running smoothly on a scroll.
It seems like you're trying to create your own list view implementation so that you can set your own layouts for each row. I don't recommend doing this. Instead, use the default list view implementation provided by Android and instead of setting a default ArrayAdapter instance on the list view, subclass ArrayAdapter, override the getView method, and return your custom layout.
I highly recommend you check out this tutorial for a more thorough explanation:
http://www.ezzylearning.com/tutorial.aspx?tid=1763429

Need suggestions for dynamically creating views in android

I am going to start one app where my activity page will contain "n" grouped views. Grouped view means "collections of views (i.e. One group can have TextView+Button+ImageView)". So the page will have "n" number of such grouped views.
I need suggestions like what would be the best practice to implement this. I could think of below ones:
1) Should a ScrollView be used (Then I will have to create groups in runtime and place one under another)?
2) Or a ListView be used (Then how can I accommodate the height of each row as grouped views height may differ from each other?)
Or is there any other way I can go along with?
Appreciate the suggestions and any sample examples if have. Advance Thanks.
Both options would work, it really depends on your use case.
Place a vertical LinearLayout inside of a ScrollView and add your grouped-views to the LinearLayout. I would recommend this if you have a relatively small number of such views (not necessarily a fixed number, but small enough that you wouldn't have to scroll many "pages" to see them all). Make sure the ScrollView has android:layout_height="match_parent" and the LinearLayout has android:layout_height="wrap_content".
If the number of grouped-views is not small, you could use a ListView and make an Adapter for it. This lets you take advantage of ListView's automatic view recycling when items get scrolled off screen.
For either case, make an XML file for just the grouped-views. In code, you would get a LayoutInflater object (usually by calling Activity.getLayoutInflater()) and call inflate(R.layout.your_grouped_views, null). If using the LinearLayout, you would add it in code with one of the LinearLayout.addView(..) methods; if using the ListView, your adapter would return the whole thing from getView(...).
create one xml layout containing the constant elements of your group view.
in you main xml layout which will be the contentView of your application, put a ScrollView and a single LinearLayout.
then in the program inflate as many views of your group view as you want.
For your answer i want to give you referance of this website, on this website you can learn create dynamic view in android...

GridLayout and dynamic views

I want to use a GridLayout to reproduce a layout similar to what we currently se on the Android Market (I mean Play Store !).
Now I managed to do something relatively similar :
This looks nice, but I do not think this would scale well with many Views if I used bitmaps instead of colors for the backgrounds of the Views. As I understand GridLayout cannot use an adapter, so I would have to manage myself the management of Views when they are shown/hidden.
Any suggestions ? I don't have to use a gridlayout if this layout is possible with another view that I can plug to an adapter.
No there is no magic solution that will auto-populate your views. This is a pretty custom case. Your best bet will be to set a few timers that will periodically load/update the content of each of the sections. You will have to create/destroy/animate all of the views yourself. But I like the idea and glad to see that you are trying to make attractive dynamic content.

Scrolling multiple images in android

I´m writing an application for Android in which I have a character that I must dress with multiple items, such as clothes, hairs, hats, earrings, etc. and on one side of the screen I need to have a container with many items inside that are available for use.
My problem is that I haven´t found any object that lets me do this simple task in android, I need it to be scrollable, and resizeable so I can place it on the right of the screen, the objects i need to add are Imageviews.
I accomplished this on iPhone with a UIScrollView but it seems that it't not that simple with Android.
Thank you.
you will use a ScrollView too, but you need embed a container of your images, like a Layout or Webview inside your ScrollView.

Categories

Resources