Feed Buzzard
  • General
  • Tech
  • World Tech
  • World Tech Code
  • Wearable Tech
  • Pokemon
  • About Us
    • Terms & Conditions
    • Privacy Policy
  • Contact
No Result
View All Result
  • General
  • Tech
  • World Tech
  • World Tech Code
  • Wearable Tech
  • Pokemon
  • About Us
    • Terms & Conditions
    • Privacy Policy
  • Contact
No Result
View All Result
Feed Buzzard
No Result
View All Result
Home Latest

Android: Vertical ViewPager –

Gordon James by Gordon James
December 11, 2020
in Latest
0
0
SHARES
4
VIEWS
Share on FacebookShare on Twitter

Development issue/problem:

Is there a possibility to create a ViewPager that rolls vertically instead of horizontally!

How can this problem be solved?

Decision No 1:

You can use ViewPager.PageTransform to create the illusion of a vertical ViewPager. For example, in order to scroll with vertical instead of horizontal dragging and dropping, you must overwrite the default ViewPager events and MotionEvents exchange before processing them:

/**
* Uses PageTransform and X and Y combination
* Takes events to create the illusion of vertical scrolling of the ViewPager
*
* Requires API 11+
*
*/
public class VerticalViewPager expands ViewPager {.

public VerticalViewPager {
super(context);
init();
}

public VerticalViewPager(context, attribute set attrs) {
super(context, attrs);
init();
}

private void init() {
// Most magic happens here
setPageTransformer(true, new VerticalPageTransformer());
// The easiest way to get rid of left and right scroll patterns
setOverScrollMode(OVER_SCROLL_NEVER);
}.

The VerticalPageTransformer private class implements ViewPager : VerticalPageTransform).

@Totally Public Invalid Conversion
Page (View, Floating Position) {

as (position

Of course you can adjust these settings as desired.
At least that’s what it looks like:

VerticalViewPager Demo

Decision No 2:

Vertical display Pager

The other answers here seem to have some problems with that. Even the recommended open source projects did not combine the current checkout requests with bugfixes. Then I found VerticalViewPager from Google, where they used a kind of DeskClock application. I have much more confidence in the use of the Google implementation than in the other answers circulating here. (Google’s version is similar to the current answer, but more complete)

Full example

This example is almost exactly the same as my basic example of ViewPager, with a few minor changes to use the VerticalViewPager class.

Fill in the image description here

XML

Add xml layouts for the main activity and for each page (snippet). Note that we use VerticalViewPager, not the default ViewPager. I’ve included the corresponding code below.

Active_Main.xml

fragment_in.xml

Code

The code for VerticalViewPager is not mine. This is only an abridged version (without comments) of Google’s source code. See this version for the latest version. The comments are also useful to understand what is going on.

VerticalViewPager.java

import android.support.v4.view.viewPager

The VerticalViewPager public class extends the ViewPager {

public VerticalViewPager(context) {
dies (context, zero);
}

public VerticalViewPager(context, attribute set attrs) {
super(context, attrs);
init();
}

@ Overwrite
public boolean canScrollHorizontale (int direction) {
returns false;
}

@ Version
public boolean canScrollVertical (direction) {
return super.canScrollHorizontal (direction);
}

private void init() {
setPageTransformer(true, new VerticalPageTransformer());
setOverScrollMode(View.OVER_SCROLL_NEVER);
}.

@up definition
public boolean onInterceptTouchEvent(MotionEvent ev) {
last boolean toIntercept = super.onInterceptTouchEvent(flipXY(ev));
flipXY(ev);
return toIntercept;
}.

@ Overwrite
public boolean onTouchEvent(MotionEvent ev) {
last boolean toHandle = super.onTouchEvent(flipXY(ev));
flipXYY(ev);
back toHandle;
}

private MotionEvent flipXY(MotionEvent ev) {
final float width = getWidth();
final float height = getHeight();
final float x = (ev.getY() / height) * width;
final float y = (ev.getX() / width) * height;
ev.setLocation(x, y);
return ev;
}.

private static end class VerticalPageTransformer implements ViewPager.pageTransformer {@Overriding of public void transformPage(show view, floating point position) {final int pageWidth = view.getWidth();final int pageHeight = view.getHeight();if (Position)

MinActive. Java

I only changed VerticalViewPager to ViewPager.

Import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentPager

the MainActivity public class expands AppCompatActivity {

Static end in NUMBER_OF_PAGES = 2 ;

MyAdapter mAdapter;
VerticalViewPager ;

Write
protected blank onCreate(storedInstanceState bundle) {
super.onCreate(storedInstanceState);
setContentView(R.layout.activity_main) ;

mAdapter = new MyAdapter(getSupportFragmentManager());
mPager = findViewById(R.id.viewpager);
mPager.setAdapter(mAdapter);
}.

public static class MyAdapter expands FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}

@
public int getCount overwrite() {
returns NUMBER_OF_PAGES;
}

Public Fragment
getItem(int position) {

switch (position) {
case 0:
gives FragmentOne.newInstance(0, color.WHITE);
case 1:
// here gives another fragment class
// if you want a completely different presentation
gives FragmentOne.newInstance(1, color.CYAN);
default:
gives zero;
}
}
.}

the public static class FragmentOne expands Fragment {

Private static end line MY_NUM_KEY = Number;
Private static end line MY_COLOR_KEY = Color ;

private int mNum;
private int mColor ;

// You can change the settings to be passed to each
static FragmentOne newInstance (int num, int color) {
FragmentOne f = new FragmentOne();
Bundleargs = new Bundle();
args.putInt(MY_NUM_KEY, num);
args.putInt(MY_COLOR_KEY, color);
f.setArgumenten(args);
return f;
}

@Override
public void onCreate(Bundle storedInstanceState) {
super.onCreate(storedInstanceState);
mNum = getArguments() != zero ? getArguments().getInt(MY_NUM_KEY) : 0;
mColor = getArguments() ! = zero ? getArguments().getInt(MY_COLOR_KEY) : Color.BLACK;
}

General view
to create the view (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view v = inflater.inflate(R.layout.Fragment_one, container, wrong);
v.setBackgroundColor(mColor);
TextView textView = v.findViewById(R.id.text view);
textView.setText(page + mNum);
return v;
}
}
setText(page + mNum).

Loan

You should be able to launch the application and see the result in the animation above.

See also

Decision No 3:

I have a solution that works for me in two steps.

  1. Create a view in the OnInstantiateItem() PagerAdapter and set it to -90 :

view.setRotation (-90f)

If you use the adapter for the fragment paging receiver, then… :

objFragment.getView().setRotation(-90)

  1. Rotate the ViewPager view by 90 degrees:

objViewPager.setRotation(90)

It works like clockwork, at least for my demands.

Decision No 4:

For those who have difficulty operating the ViewPager vertically in a horizontal direction, simply proceed as follows:

Vertical display Pager

the public class VerticalViewPager expands the ViewPager {
public VerticalViewPager(context) {
super(context);
init();
}.

public VerticalViewPager(context, attribute set attrs) {
super(context, attrs);
init();
}

private void init() {
setPageTransformer(true, new VerticalPageTransformer());
setOverScrollMode(OVER_SCROLL_NEVER);
}.

The VerticalPageTransformer private class implements ViewPager : VerticalPageTransform).

@Totally Public Invalid Conversion
Page (View, Floating Position) {

as (position

Horizontal beeper

the public class HorizontalViewPager expands ViewPager {
private GestureDetector xScrollDetector ;

horizontal view public pager {
super(context);
}

public HorizontalViewPager(context, AttributeSet attrs) {
super(context, attrs);
xScrollDetector = new GestureDetector(getContext(), new XScrollDetector());
}.

The XScrollDetector class extends the GestureDetector.simpleOnGestureListener class {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return Math.abs(distanceX) > Math.abs(distanceY);
}
}.

@Override of the public boolean
onInterceptTouchEvent(MotionEvent ev) {
if (xScrollDetector.onTouchEvent(ev)) {
super.onInterceptTouchEvent(ev);
returns where;
}.

return super.onInterceptTouchEvent(ev);
}

}

Decision No 5:

A small extension of this answer allowed me to answer my request (Vertical Look Pager, to revive a pager similar to that of Inshorts – News in 60 words).

The VerticalViewPager public class extends the ViewPager {

public VerticalViewPager {
super(context);
init();
}

public VerticalViewPager(context, attribute set attrs) {
super(context, attrs);
init();
}

private void init() {
// Most magic happens here
setPageTransformer(true, new VerticalPageTransformer());
// The easiest way to get rid of left and right scroll patterns
setOverScrollMode(OVER_SCROLL_NEVER);
}.

private class VerticalPageTransformer implemented ViewPager.PageTransformer {
private static end floating MIN_SCALE = 0.75f ;
@override
public void transformPage { view, floating position) {

as (position

I hope it helps someone else.

Decision No 6:

There are several open source projects that claim to do so. Here they are:

They have been described by their authors as obsolete:

And another thing:

Decision No 7:

Visit: https://github.com/JakeWharton/Android-DirectionalViewPager

Whether the following question can help: Vertical grid view with pages or viewer.

Decision No 8:

Just improve the @Board and @Salman66 responses to correctly convert (X,Y) coordinates to (Y,X) as the device is displayed rectangular:

…

/**
* X and Y change your touch event
*/
@ full screen Boolean
onTouchEvent(MotionEvent ev) {
gives super.onTouchEvent(swapXY(ev));
}.

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
returns super.onInterceptTouchEvent(swapXY(ev));
}

private MotionEvent swapXY(MotionEvent ev) {

// Get display size
float displayWidth=die.getWidth() ;
float displayHeight=die.getHeight() ;

// Determine the current sensor position
float posX=ev.getX();
float posY=ev.getY() ;

// Convert (X,Y) to (Y,X) taking into account the display size with
float newPosX=(posY/displayHeight)*displayWidth ;
float newPosY=(1-posX/displayWidth)*displayHeight ;

// Switching the x and y cables of the touch event
ev.setLocation (newPosX, newPosY) ;

Return ev;
}

…

However, a little more needs to be done to improve the responsiveness of the touch screen. The question may refer to @msdark, which comments on the answer @Salman66.

Decision No 9:

Import android.content.context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View ;

The VerticalViewPager public class extends the ViewPager {

public VerticalViewPager {
super(context);
init();
}

public VerticalViewPager(context, attributeSet attrs) {
super(context, attrs);
init();
}
private void init() {

setPageTransformer(true, new VerticalPageTransformer()) ;

setOverScrollMode(OVER_SCROLL_NEVER);
}

the VerticalPageTransformer private class implements the PageTransformer {

@Totaal
public invalid transformPage (Show view, floating point position) {
int pageWidth = view.getWidth() ;
int pageHeight = view.getHeight() ;

as (position

Decision No 10:

Finally, I created a new DirectionalViewPager that can scroll both vertically and horizontally, because all the solutions I’ve seen here have their drawbacks:

  1. Existing implementations of VerticalViewPager (from Castorflex and LambergaR)
    • They are based on very old versions of supporting libraries.
  2. Transformation trick with change of coordinates
    • The overcroller is always displayed in the left and right margin.
    • The page break doesn’t work properly because VelocityTracker.computeCurrentVelocity always calculates the speed in the X-axis, even if the coordinates change, probably because in this case a native call is used internally to ignore the coordinate change.
  3. See the rotation
    • Hacking, looking away from every child.
    • If you want to read the coordinates for something else, you have to change the axis.

Good luck!

Related Tags:

personal loans based on income only,low-income loan assistance,low income loans no credit checks,private emergency loans,emergency loan charity,personal loans for low income individuals,who is forced to use payday loans,what is a title pawn lender?,payday loan statistics 2018,write a short note on shg,what are payday loans,loans for low income families with bad credit,last resort loans bad credit,home loans for low income and bad credit,bad credit loans guaranteed approval,credit union payday loan alternative

Total
0
Shares
Share 0
Tweet 0
Pin it 0
Share 0
Tags: Featured
Gordon James

Gordon James

James Gordon is a content manager for the website Feedbuzzard. He loves spending time in nature, and his favorite pastime is watching dogs play. He also enjoys watching sunsets, as the colors are always so soothing to him. James loves learning about new technology, and he is excited to be working on a website that covers this topic.

Related Posts

indiabased arya south asia 46m series 14msinghtechcrunch
Latest

How will this boost financial inclusion for India’s farmers?

March 22, 2023
indiabased arya 46m 14msinghtechcrunch
Latest

What are the benefits of using Arya?

March 22, 2023
indiabased arya south 46m series 14msinghtechcrunch
Latest

How Arya is helping farmers access finance and post-harvest services

March 22, 2023
Next Post

Which Google phone should you buy when Christmas shopping?

I can’t install intel HAXM –

Be Very Sparing in Allowing Site Notifications

No Result
View All Result

Recommended

indiabased arya south asia 46m series 14msinghtechcrunch

How will this boost financial inclusion for India’s farmers?

14 hours ago
indiabased arya 46m 14msinghtechcrunch

What are the benefits of using Arya?

14 hours ago
indiabased arya south 46m series 14msinghtechcrunch

How Arya is helping farmers access finance and post-harvest services

14 hours ago
n26 900m 9b 7mdillettechcrunch

The future of banking with N26

14 hours ago

Categories

  • Fitness Trackers
  • General
  • Latest
  • Pokemon
  • Tech
  • Technology and Computing
  • Wearable Tech
  • World Tech
  • World Tech Code

Recent Posts

  • How will this boost financial inclusion for India’s farmers? March 22, 2023
  • What are the benefits of using Arya? March 22, 2023
  • How Arya is helping farmers access finance and post-harvest services March 22, 2023
  • The future of banking with N26 March 22, 2023

Categories

  • Fitness Trackers
  • General
  • Latest
  • Pokemon
  • Tech
  • Technology and Computing
  • Wearable Tech
  • World Tech
  • World Tech Code

© 2022 FeedBuzzard.com

No Result
View All Result
  • General
  • Tech
  • World Tech
  • World Tech Code
  • Wearable Tech
  • Pokemon
  • About Us
    • Terms & Conditions
    • Privacy Policy
  • Contact

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT