ysamlan / horizontalpager Goto Github PK
View Code? Open in Web Editor NEWAn Android horizontally scrolling view that snaps to child pages neatly and supports nested vertically scrolling child views.
An Android horizontally scrolling view that snaps to child pages neatly and supports nested vertically scrolling child views.
Hey!
First of all, I wanna thank you for the awesome work you did with the horizontalpager.
I use it in my project and it works very well.
Im building a launcher, where each page is a linearlayout which holds another views (images, layouts, etc..)
however, the sliding/dragging isn't smooth enough like in Helix Launcher for example (In their launcher, the widgets on the
screen are being scrolled very smoothly)
what can I do in order to get better results according to the smoothness?
I also have another problem.
The pager is becoming sluggish for 2-3 seconds at random times.
what can be the cause of that problem?
thanks i advance!@
:D
If the goal is to mimic the way Launcher does this, I believe there are two errors in HorizontalPager.
For this we need a GestureDetector. I'll try to implement this tonight.
Hi,
I am using the HorizontalPager class to flip from one image to the next. It works great! (Thanks for writing & sharing this)
One problem : There are large empty spaces between images, Not sure if I am doing something wrong or this is a limitation of the code.
This is the scenario I have within the xml:
<com.github.ysamlan.horizontalpager.HorizontalPager ...>
<ImageView ... />
<ImageView ... />
<ImageView ... />
<ImageView ... />
</com.github.ysamlan.horizontalpager.HorizontalPager >
The image pngs are thin & long - about 18 px (width) X 111 px (height)
Thanks much!
Never mind. It's my lack of understanding how events work. Is there a way to delete issues? I'll close this one, but cannot delete.
Fix:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
getChildAt(0).dispatchTouchEvent(ev);
this.onTouchEvent(ev);
return true;
}
NOTE: getChildAt uses a magic number.
Hello,
nice work. Thank you.
But I have found a bug. When switch to page 3 and rotate the screen shows page 1.
greets
why this error getting?
I wonder if we have a variable to indicate this HorizontalPager is scrolling?
I have implemented the xml version on my project and I can observe some kind of conflict beetween the page swipe and the scrolling of a listview.
If I ever scroll the list, I will not be able to swipe consistently to another view.
To be more specific if I scroll the list and then touch it to stop it, I will be able to swipe to another page. But if I scroll the list and let it stop by itself or swipe right after the scroll without a touch, I will not be able to swipe. It will register it like if I was trying to scroll again in the list.
I was having problems with this when the orientation changed. In your example it snaps to the first screen when orientation changes, but i wanted it to snap to the current screen you are on. So what i did was took the snapToScreen code and rather than grabbing the view's getWidth() i substituted the screens width in its place and called the startScroll with duration zero. here is the code to accomplish this:
public void orientationSnapToScreen(Context ctx)
{
Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int displayWidth = display.getWidth();
mNextScreen = Math.max(0, Math.min(getCurrentScreen(), getChildCount() - 1));
final int newX = mNextScreen * displayWidth;
final int delta = newX - getScrollX();
mScroller.startScroll(getScrollX(), 0, delta, 0, 0);
}
and then you just call it like this in your code:
@ Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
// realViewSwitcher is a HorizontalPager
realViewSwitcher.orientationSnapToScreen(this);
}
Hope this helps :)
Hi, is there a way when you get to the last view in the list to flip to the first view. or when you are on the first view allow scrolling back to the last view? so you would always be able to scroll left or right past the start/end. Also, is there an easy way to integrate a inflator or something to better allow for custom views?
Great job!
I tried this with a TabWidget instead of the Radio buttons. Instead of the onCheckedChangedListener I'm using an onClickListener. Though, I'm sure this applies to radio buttons too.
When a radio button is checked, we set the current screen:
mPager.setCurrentScreen(0, true);
The second parameter implies an animation for 500 ms. This makes the UI thread block, which in turn delays the Radio button update. E.g.:
Instead, we should check the button immediately (as if the animation was disabled) and then animate the page change. This is how it's done in the Music app.
Hence, we need to make an asynchronous call to snapToScreen() inside setCurrentScreen(). Post runnable? Any ideas?
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.