मैं ऐसे किसी भी व्यक्ति को अपडेट देना चाहता हूं जो एक ही सुविधा चाहें। इस सुविधा को अभी तक लागू करने के लिए बहुत सी प्रगति की गई है और अब दृश्य ठीक उसी तरह काम कर रहा है जैसा हमें इसकी आवश्यकता है।
व्यूपेजर में setPageMargin() नामक एक विधि है। यह विधि एक नकारात्मक मान प्राप्त कर सकती है जो टुकड़े/विचारों को एक-दूसरे को ओवरलैप करने के लिए बनाती है। वांछित लेआउट पर पहुंचने के लिए, हमने पहले स्क्रीन के प्रतिशत से गतिशील रूप से बाएं और दाएं मार्जिन की गणना की। यह स्थिर रूप से भी किया जा सकता है लेकिन चूंकि हम विभिन्न स्क्रीन आकारों की एक श्रृंखला को लक्षित करेंगे, यह सबसे अच्छा तरीका प्रतीत होता है।
बाद में हमने व्यूपार्जर के पेज मार्जिन को साइड मार्जिन के आकार के 2 गुना सेट किया। इससे विचार एक साथ वापस आते हैं। हालांकि, इस समय, ViewPager द्वारा एक से अधिक दृश्य प्रदर्शित किए जायेंगे।
आप सभी को छोड़ दिया है या तो बाएं और दाएं (एंड्रॉइड 3.0+) के दृश्यों में एक ट्रांसफॉर्म (स्केल) लागू करना है या उन्हें सही आकार (पूर्व 3.0) में संक्षिप्त करने के लिए उनके चारों ओर कुछ और मार्जिन जोड़ना है। ।
OnPageChangeListener.onPageScrolled() को ViewPager की स्क्रॉलिंग को ट्रैक करने के लिए उपयोग किया जा सकता है। एक चिकनी परिवर्तन प्राप्त किया जा सकता है। कोड इस तरह दिखता है:
private OnPageChangeListener onPageChangeListener = new OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
// positionOffset varies from 0 to 1 and indicates how far the view is
// from the center of the ViewPager. When a view is selected (centered), this
// value is 0.
// Fades the text in an out while the ViewPager scrolls from one view to another.
// On our final design the text views are fixed to the center of the screen and
// do not scroll along with the views.
if (positionOffset < 0.5) {
setTextViewAlpha(1 - positionOffset * 2);
} else {
setTextViewAlpha((positionOffset - 0.5f) * 2);
}
// It's surprisingly complicated to get the current object being displayed by
// a ViewPager (there's no getCurrentObject method). ScaleableFragment is just
// a custom class to allow an adapter to cache it internally and also correctly
// manage a fragment's lifecycle and restore from a saved state.
ScaleableFragment sampleFragment = (ScaleableFragment) ((ShowHeroShotImageFragmentPagerAdapter) pager
.getAdapter()).getItem(position);
// Calculates by how much the current view will be scaled down. The RATIO_SCALE
// is 0.3 in our case, which makes the side views 70% of the size of the
// center view. When centered, the scale will be 1. When
// fully scrolled, the scale will be 0.7.
float scale = 1 - (positionOffset * RATIO_SCALE);
// Just a shortcut to findViewById(R.id.image).setScale(scale);
sampleFragment.scaleImage(scale);
// Now, if not in the last element, scale the next one up (in opposite direction).
if (position + 1 < pager.getAdapter().getCount()) {
sampleFragment = (ScaleableFragment) ((ShowHeroShotImageFragmentPagerAdapter) pager.getAdapter())
.getItem(position + 1);
scale = positionOffset * RATIO_SCALE + (1 - RATIO_SCALE);
sampleFragment.scaleImage(scale);
}
}
// Once scrolling is done. Make sure the views are in the right scale (1 for center,
// 0.7 for sides). Required as the onPageScrolled() method does not guarantee it
// will interpolate to 1.0 precisely.
@Override
public void onPageScrollStateChanged(int state) {
if (state == ViewPager.SCROLL_STATE_IDLE) {
setTextViewAlpha(1);
ScaleableFragment sampleFragment = (ScaleableFragment) ((ShowHeroShotImageFragmentPagerAdapter) pager
.getAdapter()).getItem(pager.getCurrentItem());
sampleFragment.scaleImage(1);
sampleFragment.enableClicks();
if (pager.getCurrentItem() > 0) {
sampleFragment = (ScaleableFragment) ((ShowHeroShotImageFragmentPagerAdapter) pager.getAdapter())
.getItem(pager.getCurrentItem() - 1);
sampleFragment.scaleImage(1 - RATIO_SCALE);
sampleFragment.disableClicks();
}
if (pager.getCurrentItem() + 1 < pager.getAdapter().getCount()) {
sampleFragment = (ScaleableFragment) ((ShowHeroShotImageFragmentPagerAdapter) pager.getAdapter())
.getItem(pager.getCurrentItem() + 1);
sampleFragment.scaleImage(1 - RATIO_SCALE);
sampleFragment.disableClicks();
}
}
}
};
यह है। मैंने पूरा समाधान पोस्ट नहीं किया लेकिन मुझे उम्मीद है कि यह किसी और को शुरू करने के लिए पर्याप्त है।
पीएस 3.0+ पर हार्डवेयर त्वरण सक्षम करें। इसके बिना, स्क्रॉलिंग एक सैमसंग गैलेक्सी टैब 10.1 पर चंचल लग रही थी।
[क्या आप इसका वर्णन कर रहे हैं?] (Http://stackoverflow.com/questions/9816371/how-to-use-multi-pane-layouts-with-viewpager) – adneal
बंद करें, सिवाय इसके कि चयनित दृश्य पर कब्जा नहीं होना चाहिए पूरी स्क्रीन लेआउट समझाते हुए एक छवि के साथ उपरोक्त संपादन देखें। – AngraX