I want to add a number of image views to a HorizontalScrollView dynamically.
I have my scroll view:
myScroller = new HorizontalScrollView(this);
Then:
myScroller.addView(myImageView1);
This works, but I want to add more than one image view to the scroller, then it doesnt work.
Any ideas?
HorizontalScrollView can only have 1 child, so you need to put all the images inside a horizontal linearLayout and add it to the HorizontalScrollView.
HTH.
Take a horizontal scrollview, and take a horizontal linear layout inside it, then if u know how many number of images are there? take it in for loop, add them imageview one by one into linearlayout...!!
If you add ImageViews you could also use Gallery which will also scroll horizontally and you can use an adapter to set the content.
If you want to stick to the ScrollView you can only have one child, so you have to add a container like a LinearLayout where you're adding your ImageViews.
Using a HorizontalScrollView to do that is much harder than using the ViewPager class that comes in the compatibility package.
For more info, read this blog post.
ScrollView it allow only one child view,
A ScrollView should place
one child in it containing the entire contents to scroll
Related
I have two HorizontalScrollViews. If the user scrolls one ScrollView, the other ScrollView should also get scrolled. I am new to android and I wonder to know how can I achieve this?
If you want your two different scrollviews to scroll at the same time it means you only need one scroll view in which you cand put the content within the ones you have now. Try do make thinghs as simple as you can
Extend HorizontalScrollview like this: https://stackoverflow.com/a/6462630/1124160
onScroll in first ScrollView: http://developer.android.com/reference/android/widget/HorizontalScrollView.html#scrollTo(int, int)
Scroll the second one.
If your have number of items save in both HorizontalScrollView , then create a GridView and give number of columns equals to element in one HorizontalScrollView. In this way you can achieve your goal.
I have a view animator that I am adding images to dynamically via a web service call. However, the scroll bar refuses to show up no matter how many pics I add to the ViewAnimator. Thoughts?
The ViewAnimator is not a scrollable layout. Adding a childview to view animator will not show the added view if you don't have a mechanism to call showNext or showPrevious.
Maybe you want to use a ScrollView instead? You nee to create a ScrollView that contains a LinearLayout with a vertical orientation. You can now add images dynamically to the LinearLayout and the ScrollView will increase in size.
Let me try to explain what I want to achieve. Currently, I have a ScrollView as the main view for my layout and a linearLayout within that to place all of my content into.
In my LinearLayout, I have a bunch of textviews and a gallery, which extends out of the screen, so the user can scroll to see everything. It works.
Now, I want to add an expandableListView to the bottom of all that content, which is still in the linearLayout. The problem is when you expand the list view groups it doesn't affect the ScrollView. I had envisaged that when you expand a group it would make the linearLayout bigger, which in turn makes the scrollview bigger.
Is what I'm thinking achievable?
EDIT:
Ok I think the situation is that listViews are normally placed in a layout by themselves and have scrollviews already enabled. You just set it to fill_parent and it works fine. However, in my case, I'll need the expandableListView to display all content without scrolling, because my ScrollView will deal with that. I don't even think it possible?
It's difficult to answert without seeing your layout xml, but I think that if you set the android:layout_height of the linear layout and expandableListView to wrap_content, the first scrollView must scroll the whole view.
have you tried putting your expandable list into another linear layout and than put it in the scroll views default linear layout?
Can any one tell me how i can set my scroll view with both vertical and horizontal scroll ?
You can't. ScrollView is vertical scroll. HorizontalScrollView is horizontal scroll.
The only View (in the SDK) that I know of that has both vertical and horizontal scroll is the WebView. See if you can work with that. If not, you'll have to create your own View.
If you need both horizontal and vertical scrolling, you shouldn't be using ScrollViews. Instead, as this question points out, you can use a combination of FrameLayouts and RelativeLayouts to achieve the desired effect.
Is it possible to allow a griview to scroll both vertically and horizontally simultaneously in android? Please advise.
It doubt that would be possible. A GridView is based on an ArrayAdapter, having only 1 dimension for the items. How would you arrange them in a view that can be extended both vertically and horizontally?
Of course, if you just want to make it larger than the screen and use hard-coded number of rows/columns, you can put it in another scrollable view.
There are following two solutions and you can use one which fits your requirement.
You can use RecyclerView instead of GridView with a custom layout manager. You can read this code for help. Also, you can read this article on how to create custom layout manager. This article gives an example of how to create two-way scrolling grid layout.
The other solution is to use RecyclerView with horizontal scrolling Grid Layout wrapped inside a scroll view.
<ScrollView>
<RecyclerView />
</ScrollView>
use GridLayoutManager with horizontal scroll for recycler view.
The first solution is efficient in a way that it handles view recycling properly.
Hope this will help.