romandanylyk / pageindicatorview Goto Github PK
View Code? Open in Web Editor NEWAn page indicator for Android ViewPager
An page indicator for Android ViewPager
private Pair<Integer, Float> getProgress(int position, float positionOffset) {
boolean isRightOverScrolled = position > selectedPosition;
boolean isLeftOverScrolled = position + 1 < selectedPosition;
if (isRightOverScrolled || isLeftOverScrolled) {
Log.d(TAG, "getProgress: " + (isRightOverScrolled ? "isRightOverScrolled" : "isLeftOverScrolled"));
Log.d(TAG, "getProgress: " + "position :" + position + "\t selectedPosition:" + selectedPosition);
selectedPosition = position;
}
...
}
isRightOverScrolled
means that scrolled to the right page.
I think isRightOverScrolled
means scrolled to the left page.
But when I print the log, it does't show.
@romandanylyk @vdubedout Any help will be highly appreciated.
Great job on this indicator widget @romandanylyk. I am currently working on porting it to NativeScript as a plugin. I seem to have some issues with 2 of the animations (Scale & Worm).
If I choose "Scale", then the entire app/view becomes sluggish and laggy. And the indicator becomes all white (the entire row).
If I choose "Worm", and when I do the first slide, the first indicator expands to the left edge of the screen (like a long worm), and then snaps back. This only happens the first time, after that it works very well.
I can provide you with gifs if you want.
The other animations work perfectly, even the new one "Fill", which is great btw. 👍
Without diving into the code, can you please explain shortly how does it work?
Why does it have minSdk 15 ?
Hei!
Please remove the logging line ("Log.e("TEST", "onPageSelected");") from release build from the onPageSelected method. Or add an option to turn logs on / off.
Hi! I'm trying to achieve quite different behaviour, using your library.
In short: count of pages can be, i.e, 24, but indicators count should be, like, 8.
And when user has reached the end of indicators row (selected indicator position is 8, i.e.), the next move will cause the whole row to slide to the opposite direction so another "free" indicator is shown. And afterwards, currently selected indicator moves to the freshly "freed" one.
I hope i described it clearly:)
Is it possible to achive? If not, what would you suggest to change in your code to achive desired behaviour?
Hi guys! awesome job! I just added PageIndicatorView to my ViewPager and it works great!
I tried to find a way to switch between the pages by touching indicators but no success. Is there a simple way o achieve this?
Hi my bro,
Could to be change and set Custom Image for each index of indicator by programmability ?
thank.
As an enhancement :) it will be great if we could have the RTL support.
exemple of RTL viewPager (https://github.com/diego-gomez-olvera/RtlViewPager).
Currently I am just rotating the PageIndicator :p
I have a requirement to produce the following screenshot.
Currently, because it's an EditText
, I can't get any padding at the top or bottom. It's always wrapped to the text size. Can anyone think of a solution to this and how it may be implemented?
My initial thoughts are to put the EditText
inside another View
and do the background drawing inside that so we can increase the bounds. This may not be a viable solution however so I wanted to get some other people's opinions.
Wrong repo sorry!
it is a great library, but when i use it on LoopingViewPager which has only one item. it will show three
dots !
Need it with infinite viewPagers and looping.
Hey its a nice library.
I m using this with recycler view, it works fine when i scroll forward. But when i scroll backward then animation wont happen
I m using this method setSelection(POSITION); to set the dot.
But when i use this method to set the previous dot (say i scrolled reverse) the animation was not proper.
Could you help me on this.
Thanks
Cannot use piv_viewPager
to select the view pager in the layout XML file. onAttachedToWindow
calls findViewPager
, which requires that getContext() instanceof Activity
. But since the ContextThemeWrapper
may be used, the check is too restrictive.
Hi again @romandanylyk. Referring to an earlier case #7
If I upgrade to version 7 or higher, I get invisible indicator in my views. I get no crashes or exceptions. All properties are set, I get proper page count as well. ViewPager works fine. I can also see that the pageIndicator instance has a parent view. But still, nothing is shown.
Do you perhaps have any idea what this might be? I should say that my views & layouts are defined in code only, no xml. Does pageIndicator only work with RelativeLayout or can we use anything?
Version 6 and earlier works without issues.
*Update SDK and BuildTools to use the latest v26.
My project has supportLibraryVersion = "24.0.0"
But PageIndicatorView depends on compile 'com.android.support:appcompat-v7:24.2.1'
and application crashes on runtime.
Work around:
//ViewPager Indicator
compile ('com.romandanylyk:pageindicatorview:0.1.1') {
exclude group: 'com.android.support'
}
Please add it to Readme
i am making android app using nativescript ...so please tell me how to add this dependancy.
Because nativescript carousal plugin is not working and its showing "cannot read property 'PageIndicatorView' of undefined,undefined"
Hi there,
@romandanylyk I found that I can't set viewPager for indicator in xml, if indicator is placed before viewPager.
Please fix it.
app:piv_viewPager="@id/view_pager"
But it does work if set indicator after viewPager or I set it programmatically.
Thank you.
it would be good to select visually current selected item, f.e. make it bigger then the others, or smaller, etc.
Thank you.
i have used it without ViewPager,just call setSelection(position) ,and then it will change postion to target position,but at last it must return back to postion 0. amazing。
last one to first one
If you use libraries like Anko or Anvil, you create your views from Java, not XML. Often there's only the Context
contructor used, so there are no attrs passed. In that case PageIndicatorView calls init(null)
and there's a condition in initAttributes()
that won't initialize the attributes. But I don't think that's what you want. I think it should use the default attributes even if there are no passed.
Thank you for this library btw!
pageIndicatorView.setUnselectedColor(R.color.bg_white);
pageIndicatorView.setSelectedColor(R.color.bg_red); 不起作用啊
It would be nice if it was possible to style the PageIndicatorView throught a styles.xml file. The only change needed would be to declare an attribute PageIndicatorViewStyle and use that as defStyle argument in the PageIndicatorView's constructor
My code:
PageIndicatorView pageIndicatorView = (PageIndicatorView)findViewById(R.id.pageIndicatorView);
pageIndicatorView.setSelectedColor(R.color.red_e6);
pageIndicatorView.setUnselectedColor(R.color.green7e);
pageIndicatorView.setViewPager(mViewPager);
but has no effect .although change color ,but the effect no change .
PageIndicatorView pageIndicatorView = (PageIndicatorView) view.findViewById(R.id.pageIndicatorView); pageIndicatorView.setViewPager(mViewPager);
Tried re-adding support libraries but no avail. Is there a method to fix this?
Thanks in advance.
How to Show Number In Indicator
This is my grade file:
https://github.com/edx/edx-app-android/blob/a0a6b44845a438d28bb415250a8364317989d407/OpenEdXMobile/build.gradle
I just added these lines to use this awesome library:
// For the optional Nullable annotation
compile 'com.android.support:support-annotations:25.3.1'
compile 'com.romandanylyk:pageindicatorview:0.2.0@aar'
compile 'com.android.support:support-compat:25.3.1'
compile 'com.android.support:support-core-ui:25.3.1'
But getting the said error i.e. Failed to resolve: annotationProcessor
.
Attribute cannot be found error when using sample XML code provided in ReadMe.
Instead of:
attrs:piv_viewPager="@id/viewPager"
It should be:
attrs:piv_viewPager="@+id/viewPager"
android.database.Observable.unregisterObserver (Observable.java:69)
android.support.v4.view.PagerAdapter.unregisterDataSetObserver (PagerAdapter.java:305)
com.rd.PageIndicatorView.unRegisterSetObserver (PageIndicatorView.java:1114)
com.rd.PageIndicatorView.onDetachedFromWindow (PageIndicatorView.java:117)
android.view.View.dispatchDetachedFromWindow (View.java:14579)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:628)
I am getting this error reports for my app after i integrated your library in my app.
However i am not able to recreate the error myself but i am getting this error in my crashlytics dashboard.
Can you please add instagram type indicator in your enhancement .
This seems to be for iOS while noone ever had for android
https://github.com/shima11/FlexiblePageControl
Thank you in advance. @romandanylyk
The indicator's current selection won't change if the viewpager's current page changed before the view get measured, for example in the activity's onPostResume() callback.
Is there a proper reason why the selection get ignored if the view is not measured? And how to fix this? Thanks.
I have a view with 2 ViewPagers, each one with its own PageIndicatorView. Only the first one works and it actually makes the second one to move at the same time. When I swipe on the second ViewPager, the PageIndicatorView does nothing
I find that the pageindicatorview module's dependencies imported the appcompat-v7 library. But I can find any importion in all the java files in this module. So, Why are you dependent on this library?
Hi,
I've created a PageIndicator as follows:
<com.rd.PageIndicatorView
android:id="@+id/background_piv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/opcamera"
android:layout_centerHorizontal="true"
android:layout_toStartOf="@+id/background_tv"/>
My ViewPager
contains around 50 elements, the PageIndicator
works fine for the first X
pages (where X
is the number of dots that the PageIndicator can show on Screen) but as soon as I display the page X+1
the PageIndicator
doesn't scroll to the right, i.e. it stops being updated.
I'm sure I'm doing something wrong so any help will be greatly appreciated :D
Hi,
I slightly changed your sample: were added two lines to the initViews function.
The color of the indicators does not change. Can you tell me what the problem?
private void initViews() {
HomeAdapter adapter = new HomeAdapter();
adapter.setData(createPageList());
ViewPager pager = (ViewPager) findViewById(R.id.viewPager);
pager.setAdapter(adapter);
PageIndicatorView indicatorView = (PageIndicatorView) findViewById(R.id.pageindicatorview);
indicatorView.setViewPager(pager);
indicatorView.setOrientation(Orientation.VERTICAL);
//<<<< New lines >>>>
indicatorView.setUnselectedColor(R.color.google_green);
indicatorView.setSelectedColor(R.color.google_yellow);
}
Regards,
Michael K
Hello,
The current position of the PageIndicatorView is not saved when recreating the activity/fragment, as it is a custom view, I think it will be great if the PageIndicatorView could restore it state itself.
Workaround : Implement the onSaveInstanceState (Activity/Fragment) to store the PageIndicatorView current position and set it on the onCreate method.
Br.
Hi
My Name is mahdi Im 16 years old Ifrom Iran
VpStoreImage.setCurrentItem(nevao_engin.get_CorrectImageStore().length() - 1);
whene i set selection Whene
PageIndicatorView.setAnimationType(AnimationType.THIN_WORM);
Selection Item is Fin not Circle
Thanks For Good Library
Setting the android:padding
property into a PageIndicatorView
has no effect.
I'm aware of the app:piv_padding
property, but that serves a different purpose. What I desire is to set a padding around the page indicators.
<com.rd.PageIndicatorView
android:layout_width="wrap_content"
android:layout_height="24dp"
android:background="@android:color/white"
android:padding="24dp"
app:piv_animationType="slide"
app:piv_viewPager="@id/view_pager"/>
I believe the same would apply to the other android:padding
variants, such as android:paddingStart
, android:paddingEnd
, etc
Hi @romandanylyk ,
I've created custom FragmentPagerAdapter with width of page = 0.9f.
public float getPageWidth(int position) {
return .9f;
}
app:piv_padding="5dp"
app:piv_radius="5dp"
app:piv_animationType="worm"
app:piv_dynamicCount="true"
app:piv_interactiveAnimation="true"
As the result indicator can't scroll to the final position. Last point should be circle, not oval. Please look at the screenshot.
Thank you.
I have 5 fragments, of which only 3 are displayed, the others will be skipped. But the piv always shows 5 dots:
<com.rd.PageIndicatorView
android:id="@+id/pageIndicatorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="false"
android:layout_centerHorizontal="true"
android:layout_centerVertical="false"
android:layout_marginTop="20dp"
android:elevation="5dp"
app:piv_count="3"
app:piv_dynamicCount="false"
app:piv_unselectedColor="#000000" />
hi
i not good at engilish
how set size for view pager inficator
thanks
It would be nice to have an xml attribute like visibilityWhenCountOne
(or a better name) with the choices of "visible" "gone" and "invisible"
Library modules (except official support library) generally prefix all their resource name with thier initials so that they won't collide with each other which will fail the build. For this project piv_ seems good.
BTW the strings.xml inside the library module should also be removed, as it is unused and developers are highly likely to use the same name which will produce an overriding of resource unexpectedly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.