I have an android project that my client is requiring me to have a ViewPager similar to the image below.
Showing three panel at a time. The current selected panel will show full at the center, the panel before the selected one (if there is) will be shown half, and the panel after the selected one will be shown in half as well.
Do you guys have any idea in how to do this? Still new in Android an im slowly getting lost when it comes to this kind of stuff?
Here is the code that i have so far that will only show one panel.
ViewPager viewPagerShopPortfolio = (ViewPager)
mShopPortfolioImageAdapter = new ShopPortfolioImageAdapter(getChildFragmentManager(), portfolioListingModelList);
viewPagerShopPortfolio.setAdapter(mShopPortfolioImageAdapter);
And this is how my app looks like right now which only shows one panel.
Well, i found a second solution for this using the following codes:
XML:
<android.support.v4.view.ViewPager
android:id="#+id/viewPagerShopPortfolio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:clipToPadding="false"
android:paddingLeft="60dp"
android:paddingRight="60dp"
android:background="#color/colorFontWhite" />
Java:
ViewPager viewPagerShopPortfolio = (ViewPager) view.findViewById(R.id.viewPagerShopPortfolio);
viewPagerShopPortfolio.setPageMargin(30);
Here is the following result:
You can override getPageWidth method of PageAdapter. For example return 0.7f to have all child pages span only 70% of the ViewPager's width.
Or you can use library:
https://github.com/Pixplicity/MultiViewPager
More information about that lib you can find in [that][2] answer.
Related
I am working on an android library called MaterialViewPager
I have five tabs, the text of some of them are little longer. I purposely want to show full text in tabs (finance related application). Right now the page titles are getting truncated and replaced with ... (e.g. Exemption is being replaced with Exe...).
I could not find any setting that forces tab to be of full text/width.
Has anyone used this library before have achieved it? If not, is there any alternative library that can help me achieve it?
To Force tab to show Full text try to set the TabLayout property tabMode to scrollabale. TabMode is having two values
1. fixed - 1
2. scrollable - 0
set it Like:
app:tabMode = "scrollable"
Answer was simple. I just had to add a custom tab
<com.astuetz.PagerSlidingTabStrip
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#id/materialviewpager_pagerTitleStrip"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:pstsPaddingMiddle="true"
app:pstsDividerPadding="20dp"
app:pstsIndicatorColor="#FFF"
app:pstsIndicatorHeight="2dp"
app:pstsShouldExpand="false"
app:pstsTabPaddingLeftRight="10dp"
app:pstsTabTextAllCaps="true"
tools:background="#A333"
/>
Notice that I set pstsShouldExpand to false. This makes sure that the tab width is not distributed, hence we can see full text.
Note - This makes the tab width uneven.
Basically I'm trying to create finite sliding tabs (say, 2 weeks). The middle tab is the current date, You can't scroll into future dates, but can go back as far as the tabs will take you. This should be based on a calendar (legit dates, etc.) and look like a timeline. A good example is the Fitocracy app, which I'm trying to imitate.
Any ideas are greatly appreciated!
Look at this Infinite ViewPager lib (sample below) and PagerSlidingTabStrip lib for smooth tabs names.
//XML
<com.antonyt.infiniteviewpager.InfiniteViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
// Code
PagerAdapter wrappedAdapter = new InfinitePagerAdapter(yourFragmentPagerAdapter);
viewPager.setAdapter(wrappedAdapter);
I think that using 2 libs above is enough to archive what you want. Hope this help!
FIRST PAGE
[/IMG]
SECOND PAGE
[/IMG]
I want show my two pages like this, When loading first page the second page title should be shown indicating the user about a second page. How can I achieve this?, I can put two tabs or viewpager with view pager indicator, i want that functionality but actually what I ask here is the view that is marked the image, the next tab to display half of its title indicating the user of next page.
Thanks in advance..
You can directly use ViewPager with PagerTabStrip provided in android support-v4 library.
Download android Support-V4 library here
Then extract the android Support-V4 jar and paste into your project libs Folder.
Right click and Add to build path.
Now use View pager with PagerTabStrip in your Main layout as:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="#+id/viewpage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/pagetab"
>
<android.support.v4.view.PagerTabStrip
android:id="#+id/pagetab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#333333"
android:background="#ffffff"
android:layout_gravity="top"/>
</android.support.v4.view.ViewPager>
</RelativeLayout>
Now populate the ViewPager using Adapter in Main Class .see here
Now you can Achieve What you want.
I strongly advise you to use a library, instead creating the widget yourself.
That said, this library suit your requirements. It’s really easy to implement it:
PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
tabs.setViewPager(yourViewPager);
You can found a complete implementation here
I am trying to figure out how to make a swipe view without a tab layout.
In the figure above,
1. I want to make a swipe view that can navigate page left and right.
2. Icon 1 is a global menu that needed to be there all the time while swipping.
3. Icon 3 is a bottom bar. How can I make like that way?
Any kind of suggestions and tutorial links would be appreciated. Thanks in advance.
i don't have any links for the same,but still i will tell you the very simple logic to create:
1.First remove the title bar using
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
2.Use the following Structure
<RelativeLayout>
<ViewPager android:layout_height="fill_parent"
android:layout_width="fill_parent"> //full screen
<RelativeLayout android:id="#+id/header"> -->for header
android:layout_alignParentTop="true"
</RelativeLayout>
<RelativeLayout> -->for inicators
android:below="#+id/header"
</RelativeLayout>
<RelativeLayout> --> for footer
android:layout_alignParentBottom="true"
</RelativeLayout>
</ViewPager>
</RelativeLayout>
3.now make the images for header and footer and set as background.
4.for view pager indicator go Through This Post.just download it and import in your eclipse and set as a lib in your project. how to use circle pager indicator Check My Answer.
and you are done now!!
You can simply use for example a ViewPager as explained in the official documentation because it's not mandatory to have tabs.
http://developer.android.com/training/animation/screen-slide.html
There's a full example available in that link.
If you need also to display dots for your slides, you can take advantage of this library as pointed out by other users: http://viewpagerindicator.com/
Check this library I think this is what you need
and you can customize it as per your needs
https://github.com/pakerfeldt/android-viewflow
I have implemented a scrollable tab + swipe, everything works fine.
However I have some issues related to the current PagerTabStrip :
1. I can't make the current title Bold
2. Can't choose the default tab I want to display (e.g : the tab with position 2) when rendering the view, like the tabs in the Google Play app
3. The first and last tab have respectively a margin on the left and the right, can I set it to 0dp ?
This is what I could do for styling the tabs :
Java :
strip = (PagerTabStrip) findViewById(R.id.pager_tab_strip);
strip.setTabIndicatorColorResource(R.color.light_blue);
strip.setDrawFullUnderline(true);
Layout :
<android.support.v4.view.PagerTabStrip
android:id="#+id/pager_tab_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#drawable/pagertitle_border_bottom"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:textColor="#color/light_blue" />
Can anyone help me with the 3 points ? Thank you.
Well, I actually found a proper solution for that. Forget about PagerTabStrip ;)
Apparently, Google released a sample app that features the exact source code they used in Google Play app. It's super easy to use. Download the sample app and copy two files from there: SlidingTabLayout.java and SlidingTabStrip.java.
Then in your layout XML, add the following above the ViewPager (change com.example to your package name):
<com.example.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_marginTop="5dp"
android:layout_weight="1.5"
android:layout_width="match_parent"
android:background="#android:color/white"
android:layout_height="0dp"/>
And add the following to the activity after you initialize the ViewPager:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(new GridPagerAdapter(getSupportFragmentManager()));
// Initialize the SlidingTabLayout. Note that the order is important. First init ViewPager and Adapter and only then init SlidingTabLayout
mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
mSlidingTabLayout.setViewPager(mViewPager);
}
SlidingTabLayout's API allows you to easily do basic styling such as, changing the tab color, the divider color, the indicator color, etc.
One more important thing, the SlidingTabLayout that Google provided works well when you have many tabs. But, if you have, for example, three tabs, you'll see that all the tabs are aligned to the left and there's a big gap between the last tab and the width of the view.
To overcome this, modify SlidingTabLayout.java after line 173 just below TextView textView = new TextView(context); add the following line:
textView.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
Now the space among the tabs will be divided correctly:
Have a look at this. This guy explains very clearly how to use Sliding Tab Layout
Understanding Sliding Tab Layout
For any customization
Change the code in the class SlidingTabLayout.java