Create multiple horizontal scrolling layouts within a scroll view - java

So I have a Scroll View which contains a relative layout. I want that relative layout to have 3 or more layouts that can be scrolled. I know how to implement that with HorizontalScrollView, but before execution, I have no idea how many elements the HorizontalScrollView is going to have. Should I use ViewPager for this? What I would like the most is a HorizontalListView.
Would you recommend something like this:
https://github.com/sephiroth74/HorizontalVariableListView
Or should I add views programmatically in a HorizontalScrollView?

ScrollView is widget that should be used to keep static layouts inside. In general - ones that just are ~slightly bigger that the screen.
If you need something really dynamic you should use elements based on adapters like ListView, or ViewPager.

Related

How do I add a custom view to a layout programatically Android Studio

I want to implement a custom view into a LinearLayout that's inside of a ScrollLayout, but I don't know how many views I'll implement into the LinearLayout. What I want is like a scrolling box of interactive cards. How can I do this?
What I want is like a scrolling box of interactive cards.
Use RecyclerView instead of LinearLayout.

Scrollable Views Interacting with other child views like Google street View

I intend achieving a layout similar to what is shown.
I have tried achieving similar behavior with Bottom sheet, percentFrameLayout, ScrollView and Coordinated layout on different occasions, but I've not being able to achieve something similar to the view that (possibly a fragment) that is scroll from the bottom of the screen and interact with other child views on the screen like the tab and the refresh button.
Any guideline and directions on how i can do this ?
You can use a RecyclerView for the cards and leave your toolbar and main content on a FrameLayout at the same level as the map. And of course a coordinator layout and proper behaviors on each element.
By doing this your recycler view will be able to interact with the toolbar and still be independent from the map.
In other words, you can reduce your problem to a single recyclerview scroll with a toolbar by making a space on the beginning of the vertical recyclerView.

relative positions in android UI

i have a problem in designing user interface and layouts. i want that some views relates to others. for example a button related to a TextView and when i sat margin top, it calculates from that TextView not screen top. how i can do this?
Have a look at Relative Layouts. They are the answer to your question. You can relate a view to another by setting it toLeftOf, below, alignParentTop or any other combination.
Use a RelativeLayout and Views will be positioned relative to other Views.
From what you have written it seems like you could group the TextView and Button into a container view, like a RelativeLayout, and fit them inside there with the appearance you would like. Then you can set the margin of the Relative layout.
Edit: Clarity

Android - Dynamically add items to ListView using existing XML layouts?

I have a ListView that I want to dynamically add items to. For the items, I want to use a specific layout that I have defined in XML. How do I go about adding the items to it and have each item use the specific XML layout?
Do I have to create an adapter and jump through all those hoops? There is only a handful of items that I need to display. Each item has a few text views that need to be populated as well as an image that needs to be displayed.
If I go with the Adapter route, I need to basically creating a custom object/class that contains the text for each textview as well as the URL of the image I'm downloading. Seems like way overkill for just displaying a handful of listview items.
Isn't there someway I can just iterate through my items, inflate a view for each and add them to the listview?
you want to use a ScrollView for your purpose. works just like a listview, except the rule is a ScrollView should only have one child layout (that layout would be containing all the items you want to put inside). inflate a layout, then addView(). rinse repeat.
Unfortunately you do have to create an adapter. SimpleAdapter is about as easy as it gets. Here's a nice example that'll have you up and running in a few mins:
http://ykyuen.wordpress.com/2010/01/03/android-simple-listview-using-simpleadapter/
Either you can create an adapter which is really not all that complicated, or you can use a ScrollView with a LinearLayout inside and inflate yourself. Either option is reasonable, depending on your requirements, but inflating yourself and adding the views to the ListView manually isn't one of them. By the description you give, it sounds like you might just want to go the LinearLayout route.
Put a ScrollView with a LinearLayout inside in your main layout XML.
For each child:
Inflate the view for the child item and populate the fields accordingly.
Add the child view to the LinearLayout using addView.

which layout would be the best solution?

I am trying to create a layout that can fits my situation where I will need to have a layout that keeps the views like imageview or textview or probably a combination of a few. while on the top right of it, i will need to have two buttons on top.
However, this layout has to be dynamic where I can select whether if I want to show the buttons or not. How should I go about it?
You can use any layout you want really, although it sounds like a horizontal LinearLayout would fit your situation the best.
You can then control visibility of individual elements via setVisibility(View.GONE) and setVisibility(View.VISIBLE), or simply through addView.

Categories