How to make the viewpager below the tab in TabCarouselLibDemo? - android

The TabCarouselLibDemo source is here. Thanks for the author's work.
The demo shows the ViewPager is below the tab, but in the xml, the ViewPager seems that it is at the top of the tab.
I think if you can see the demo you will understand what I mean.
I have a question about how to make the ViewPager below the tab? I have seen nothing about it in the code.
It makes me feel uncertain.
Thank you in advance!

It has to do with how RelativeLayout draws its children. If the ViewGroup was a LinearLayout and the orientation was set to "vertical", the carousel would be placed below the ViewPager, like you're thinking. But that's not how RelativeLayout works.
As far as the content in the ViewPager being below the carousel, you have to look at the custom Adapter used. There's a layout called "faux_carousel" that's used to create a layout with the same dimensions as the actual carousel, without showing the carousel itself. That layout is placed at position "0" in the Adapter so that all of the other content (that's in the ViewPager) will rest below the fake carousel and therefore the real one too.

Related

How to implement a cover view viewpager

I want to implement a viewpager like the one below
I found this example Cover Flow feature using view pager android but it only inflates the image to the left and does't show the other two to its side.
Try this
viewpager.setClipToPadding(false);
viewpager.setPadding(left,0,right,0);
To set margin between two pages
viewpager.setPageMargin(10);

How to create swipeable view only to half?

I tried searching but can't seem to find a swipeable view that can only swipe only half.
Here is an example image.
I tried creating two pages (in a tab) that contains image 1 and image 2, but the animation is having two stars when you are in mid-swipe.
Cheers.
Edit: found a working example. I will just try mimicking this one.
https://github.com/baoyongzhang/SwipeMenuListView
You can use two ViewPager to serve for this purpose and customise them in a way so that one ViewPager change the other. In this way, I will give a feel that it is being swiped from half.

How can I customize view pager in android

I am new to view pager in android. I want to make my view pager like this.
In this my problem is to making the circles with the number showing. How can I achieve this in android.
I have tried the view pager customizations methods but I didn't succeed. Please tell me how can I achieve this type thing in android.
I have written true ViewPager indicators similar to PagerTabStrip which are embedded in the ViewPager and they are a pain.
This indicator looks like it might be separate from the ViewPager anyway, so here is an easier way to do this sort of thing:
Make a custom widget that extends LinearLayout. This will be a horizontal layout. Have it also implement ViewPager.OnPageChangeListener.
In the setup of this widget, you add ImageViews to the LinearLayout with the drawable set to the circle of your choice. Use ViewPager.getAdapter().getCount() for the number of circles to add.
in the onPageSelected() method, use the position argument as the index to LinearLayout.getChildAt() to get the ImageView that represents that selected page. Set the drawable to the image that represents your selected page. Don't forget to reset the ImageView that was previously selected!
Call ViewPager.setOnPageChangeListener() with your widget.
Now if you also want to put a number in there, the views you add to the LinearLayout will need to have a TextView as well. You'll also need to get the data to go into the TextView, perhaps from a custom method on the PagerAdapter.
Also, I'll bet the app you are referencing has an animation showing the bubble expanding.
I'll try to post some code later.

Dynamic Center Aligned ViewPager

I'm having trouble aligning the fragments to the center of the view pages, in a way that the user can see multiple fragments on the screen. This problem has already been solved before, but not when the fragments have different size.
Can ViewPager have multiple views in per page? is one link that I used. The pagercontainer solution on it works but is very slow. My solution was to set ViewPager padding through setPadding(int, int, int, int) method and false for setClipToPadding. Doing so makes the fragments look as if they're aligned in the center, but assumes that all fragments are the same size (since setPadding is a global setting for a View). So having different fragment sizes just completely messes the alignment.
I was hoping if someone knew how to make it so that the current fragment in view pager can be aligned to center without the use of padding. That way one could have different fragment sizes. Alternatively, could someone suggest how to achieve center alignment with padding with variable fragment sizes?
PS: I've searched everywhere online and couldn't find a solution.
Rather than aligning the fragment inside the viewPager, why dont you try putting all your elements in a layout and then align it to center(inside the fragment).
Make viewPager as wrap_content. and make fragment main layout params as wrap_content too.
If this does not help you. You can share your layout.Also, add one more tag to your question - "android_layout"

How do I add a ViewPager as the top item in my 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.

Categories

Resources