机器人 - 传送带状部件,其显示的左和右元素的一部分带状、机器人、部件、元素

2023-09-05 07:59:03 作者:李兆香

所以,我搜索高和低,但找不到一个回答我的问题。我基本上需要的是Android的ViewFlipper或ViewPager规定的行为,但我想显示的左,右视图部分,以表明使用者有,而不必选择的观点占据了整个屏幕元素滚动,

So I've searched high and low but couldn't find an answer to my question. What I basically need is the behavior provided by Android's ViewFlipper or ViewPager but I want to display portions of the left and right views, to indicate the user there are elements to scroll, instead of having the selected view occupying the whole screen.

我也想了一些效果添加到左侧和侧视图,如调光和缩放再往下一点。是否有可能与股票ViewFlipper或ViewPager做或做我必须推出自己的视图组,点菜的Cover Flow(http://www.inter-fuser.com/2010/01/android-coverflow-widget的.html)?

I would also like to add some effects to the left and side views, like dimming and scaling then down a little. Is it possible to do it with the stock ViewFlipper or ViewPager or do I have to roll out my own view group, à la cover flow (http://www.inter-fuser.com/2010/01/android-coverflow-widget.html)?

(PS我不希望使用的库部件,该部件很烂)。

(P.S. I don't want to use the Gallery widget, that component sucks).

这就是我们需要显示视图一旦被选中(左和右的观点依然显示):

This is what we need to display once a view is selected (left and right views are still displayed):

零时左右将转变主视图中出,调光,降低了一点,做相反的下一个或previous视图。

Flinging left or right would transition the main view out, dimming and reducing it a little and doing the opposite with the next or previous view.

推荐答案

我想给一个更新的人谁可能需要同样的功能。很多已经取得了进展,以实现此功能到目前为止,现在的观点是工作正是因为我们需要它。

I would like to give an update to anyone who might want the same feature. A lot of progress has been made to implement this feature so far and now the view is working exactly as we need it to.

该ViewPager有一个名为setPageMargin()的方法。该方法可以接收一个负值,这将使片段/次,以相互重叠。到在所需的布局到达,我们首先动态地由屏的百分比计算出的左,右边缘。这是可以做到静态很好,但因为我们将针对各种不同的屏幕尺寸,这似乎是最好的办法。

The ViewPager has a method called setPageMargin(). This method can receive a negative value which will make the fragments/views to overlap each other. To arrive at the desired layout, we first dynamically calculated the left and right margins by a percentage of the screen. This can be done statically as well but since we will be targeting a range of different screen sizes, this seems to be the best approach.

后来我们设置ViewPager的页边距,以侧边的2倍。这使得意见弹回在一起。然而,在这个时候,将有更多的比正在被显示的ViewPager一个视图。

Later we set the ViewPager's page margin to 2 times the size of the side margins. This makes the views snap back together. However, at this time, there will be more than one view being displayed by the ViewPager.

你所剩下要做的就是要么应用变换(规模)向左侧和右侧(安卓3.0+)观点或周围添加一些更多的利润给他们缩小到合适的尺寸(pre 3.0)。

All you have left to do is to either apply a transform (scale) to the views to the left and right (Android 3.0+) or add some more margins around them to shrink them to the right size (pre 3.0).

的OnPageChangeListener.onPageScrolled()可以用于跟踪ViewPager的滚动。平稳 变换可以实现。在code是这样的:

The OnPageChangeListener.onPageScrolled() can be used to track the ViewPager's scrolling. A smooth transformation can be achieved. The code looks like this:

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();
            }
        }
    }
};

这是它。我没有张贴了完整的解决方案,但我希望这是足以让别人开始。

This is it. I didn't post the full solution but I hope this is enough to get someone else started.

P.S。在3.0+启用硬件加速。没有它,滚动看着波涛汹涌的一个三星Galaxy Tab 10.1。

P.S. On 3.0+ enable hardware acceleration. Without it, the scrolling looked choppy on a samsung galaxy tab 10.1.

 
精彩推荐
图片推荐