I'm trying to create a layout for my activity, but am not sure what the best way to do this is. What I want is a ViewGroup on top with some user's information. Then, below that (filling the rest of the vertical space), I have a ViewPager that hosts two ListFragments. Both ListFragments contain dynamic feeds relevant to the user.
This works fine, but what I would like to have is something that would scroll the top profile stuff out of view as the ListFragments in the ViewPager is scrolled. Attaching HeaderViews to the ListViews don't make sense since I only want the user to swipe between feeds not the feed + static HeaderView, and neither does putting the ViewPager + ListViews in a ScrollView root. Any ideas on a good way of making this layout?
Related
I want to have ScrollView Inside a Fragment that contains a TabHost as you can see from the screen-shot
it's composed by two sections:
Header: in my case it's an image, I want this section to scroll
TabHost: contains three Fragments one of them is a ListView
What I have tried ?
I tried to create a scroll view and a list view inside the TabHost, everything is fine for the two first tabs, but in the third one which is a ListView, the items are not displayed.
After some research, I figured out that we can't have a ListView inside a ScrollView.
So what is the best approach to create a view like described here is a screen-shot of what I want to create:
In fact there's a way to implement ListView in ScrollView. But with this solution, ListView acts like a LinearLayout in memory.
btw: I used it before and working nice, saves the day.
Don't use listviews in scrollviews they say, well, okay, but how do you fix this?
I have a viewpager with some lists in it (mockup)
above that, I have a tabindicator and some other information that doesn't change when you go to another tab.
My problem is that I always want to scroll the complete view (so content, tabindicator and viewpager).
If you scroll down, only the fragment with the listview (=tab content) should be visible and scrollable.
I don't want to put the content view and tab headers in a listview header because I don't want them to change every time I go to another tab (swipey tabs, so the user will see it)
What's the best way to do this?
Photos in this layout can be swiped left and right, and swipe should be 'intelligent', like switching between photos and NOT like just horizontal scrolling of photos.
2 implementations that come to my mind:
HorizontalScrollView (but swiping is dumb)
ViewPager (but there is no way to see adjacent photos)
So, basicly I need a ViewPager for photos that can show adjacent photos.
Is there a robust solution for this?
For cool swiping action viewpager is the best. And you won't have problems with memory. BUT I have no idea how to make view pager part of listview.
If you have final number of items you can use Android Gallery widget which is deprecated since api 16 but does exactly what you need, the main problem is that it cant reuse gallery items inside the adapter.
You also can try this:
Horizontal list view
I have used TwoWayView to implement my layout.
It's better than HorizontalView, cause it re-uses views (like ListView).
I have a vanilla "News" app, where the main page is a ListView that scrolls vertically with a list of articles (thumbnail, title..etc). This works just fine, but now I want to add a horizontal article/photo rotator as the top item in that list. I don't really care if it's technically in the list or not, but it should scroll up/off the screen when the list is dragged...etc. I assume(d) it should be in the list, but am quite new to Android and don't know if there's a better solution.
After an entire day of searching around, I'm still empty-handed - don't know how to add it or even if it's the right method. I'm using a ViewPager for my gallery view (when they click a photo), and that seems to be working fine...but that's the entire view... and this one already has an adapter that populates the listView... I hope I'm just over-complicating something.
TLDR:
1) Can I add a ViewPager as top item in a ListView?
2) How would one go about doing it?
3) Is there a better solution?
Note: android:minSdkVersion="8" android:targetSdkVersion="15"
You can use addHeaderView() from the ListView API to set a header. It can be any View, so also a ViewPager. I think you'll have to add it programmatically. Set the height of it correctly though.
i'm not sure i understand your question. ViewPager is a view like any other, so in your ListView's adapter's getView() method, return a view that contains a ViewPager.
ViewPager is a topic in itself, so if your problem is that you don't understand ViewPager, read these links,
http://developer.android.com/reference/android/support/v4/view/ViewPager.html
http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
if you are using API level 8, you should use the ViewPager and friends from the compatibility package.
that all being said, i wonder if you will have trouble putting a scrollable view inside a scrollable view. i know ViewPager contains code to pass off any gestures to child views if it decides it cannot handle them. i can't say if ListView has the same smarts.
I am trying to make a small dynamic book on Android.
I currently have a viewFlipper and gesture detector to swipe between the different pages in the book. This works ok if it is a fixed number of pages to a book, but I want to make it dynamic and also memory efficient by saying:
-create a linear layout with a scrollview, put this into the view flipper
-load content to that view
-on page swipe, animate to next page view but refresh the linear layout and load page2 content..etc
-on page swipe to go back a page, refresh view and load that page numbers content..etc
is there a way of doing this? instead of creating a lot of pages and overloading the memory?
A good solution would be to use a ViewPager with your own custom PagerAdapter. In the OnPageChangeListener you would load the next piece of content and then call notifyDataSetChanged() on the adapter.