Today, I was going to make an ViewPager app by Android Studio. I have added support-v4 25.3.1, but I cannot find the ViewPager in the Palette. Can someone tell me how to find it?
Gradle
Palette Search Result
I think the ViewPager purposely not shown in the palette, I can't find it either on my Android Studio.
However, you can add it manually in the XML, for example:
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"/>
After that, try to ctrl/command + click on the ViewPager in XML. If it's opening the ViewPager java class, that means you already have added the support-v4 library(including ViewPager) on your project.
Related
I am using ViewPager with PagerTabStrip:
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTabStrip
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"/>
</android.support.v4.view.ViewPager>
And I would like to accomplish my tabs to look like this as Google recommends:
I have two tabs and I would like for each of them to be fixed and take 50% of the screen. I was looking through the options in XML and programmatically and can't find anything useful.
How can I accomplish that? Thank you.
I'm not sure about android.support.v4.view.PagerTabStrip. But you can use alternative library for getting this effect, i use it in my one project and it works well. After you add the lib to your project, set pstsShouldExpand to true
You should use android.support.design.widget.TabLayout instead of PagerTabStrip.
For the past hour, I've been looking at how to add support libraries to your build path so that I can learn how to use ViewPager. But for some reason, after I add the jars to my build path and clean the project, nothing new shows up in my palette and if I try to copy and past some XML code for a ViewPager in, it doesn't recognize it in the build path! I really have no idea what's going wrong here. Any advice would be greatly appreciated.
Can you post any screenshot or something? It'll be easier for everyone to help you fix the issue.
Anyway you will need to add android-support-v4.jar to use ViewPager. Usually when you add this jar to libs folder and build path, then you can add code to your xml file just like this (it also didn't show up in my palette):
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test.MainActivity" />
There's an easy way to check your issue.
Create a new Android application in Eclipse/Android Studio
When it asks you to create a activity or not, choose Tabbed Activity and then choose ViewPager in Navigation Style combo-box
Once the project is successfully compiled, customize it the way you want or compare it to your own project to check if you're missing something. Good luck!
what I need here is actually difficult to express in words. I am using viewpager to transact between fragments in my android app. But I also want to show which fragment user is seeing currently by showing small dots below.
Please see the image to get a clear view of what I am trying to say. So, is there any library or something to achieve this.
Please let me know. Thanks in advance. :-)
1)First of all download ViewPagerIndicator Library Project from this Location :: http://viewpagerindicator.com/
2). Add that Project as Library in your Application.
3). Add this code in your XML where you have define ViewPages as well.
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="30dp"
android:layout_centerHorizontal="true"
android:padding="10dip"
app:fillColor="#FFFFFF"
app:pageColor="#000000"
app:radius="5dp"
app:strokeColor="#C0C0C0"
app:strokeWidth="1dp"
/>
4). Create Reference in Activity side eg: private CirclePageIndicator circlePageIndicator;
5). Create Object eg:circlePageIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
6). Pass ViewPager Object into this Method
circlePageIndicator.setViewPager(viewPagerObj);
It is call PageIndicatior. This is library that you can use for implementation
https://github.com/JakeWharton/Android-ViewPagerIndicator
I m still new to android and working on my first application. so far so good. among others the app will contain a ViewPager to switch between different xml layouts through swiping. this works nice.
however I would like to use the ViewPagerIndicator to indicate the position of the displayed template.
so i tried to include the code based on different tutorials/ instructions to my project but the templates/ ViewPager wont show anymore, the app breaks at that point. Thanks for any hints in advance ;)
here is the code + logCat
And in the xml you have:
<com.viewpagerindicator.TabPageIndicator
android:id="#+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
But you are using UnderlinePageIndicator in your code, so it should be:
<com.viewpagerindicator.UnderlinePageIndicator
android:id="#+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
If it's not a typo, your missing a paranthesis in this line:
UnderlinePageIndicator indicator = UnderlinePageIndicator)findViewById(R.id.indicator);
should be
UnderlinePageIndicator indicator = (UnderlinePageIndicator)findViewById(R.id.indicator);
Testing other components in android support library,
On device classLoader can't find ViewPager however it can find other support components FragmentActivity, Fragments etc . ( using V4 as well as V13, gives same result)
What's special with ViewPager ? Does it depends on another support components to work ? (Like Fragment needs FragmentActivity)
NOTE: I think I'm properly exporting support library as dependency, else Fragment would also not have worked.
You should reference it like this:
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<v4support:ViewPager> is not correct. you need the whole package name in the xml.
android.view.ViewPager is present in Android 3.0 and later. The support library version has a different package: android.support.v4.view.ViewPager.