android ViewPager customizable

佐手、 提交于 2019-12-22 11:35:13

问题


I need to implement a scroll view as shown:

That is, in "idle" state image "1" is visible in full size and image "2" is visible partially (thus giving a clue to the user that he can scroll the content). After scrolling scrool view must not stay in intermediate state and scrolling must be completed (like iOS's Scroll View does when "Paging Enabled" is turned on):

I refused to use HorizontalScrollView, because it has nothing similar to "Paging Enabled" property.

After googling, I came across android.support.v4.view.ViewPager. It's scrolling behavior is perfectly what I want, but I have no good idea how to support "partially visible" next image in ViewPager? Technically, what should I return in the

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)?

For the present, my code is

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    View view = inflater.inflate(R.layout.stage_select_image_layout, container, false);
    ImageView imageView = (ImageView) view.findViewById(R.id.stage_select_image_layout_image);
    imageView.setImageResource(m_imageResourceId);
    return view;
}

But it results in "exactly one image per page" behavior, not what I want (see the very first figure).


回答1:


This does the trick:

    ViewPager pager = ...;
    pager.setOffscreenPageLimit(2);
    pager.setPageMargin(-200);



回答2:


The easiest thing to do is, is in your PagerAdapter, implement an override for getPageWidth. The return value is a percent that the view takes up of the total space.

@Override
public float getPageWidth(int position) {
    return 0.75f;
}



回答3:


Use the widthFactor attribute of the ViewPager's LayoutParams. It should scale it so you can see a little of the next page.



来源:https://stackoverflow.com/questions/13050720/android-viewpager-customizable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!