如何在pagerAdapter中滚动滚动

时间:2012-02-12 18:23:39

标签: android

例如:我在PageAdapter中有2页。当我转到第二页时,我点击“锁定”按钮,水平滚动关闭。我点击“解锁”,然后再次滚动。块滚动怎么样? 代码:

public class slide extends PagerAdapter
{

List<View> pages = null; // empty list views

public slide (List<View> page)
{
    this.pages = page;
}

@Override
public int getCount() 
{
    return pages.size();
}

@Override
public boolean isViewFromObject(View view, Object obj) 
{
    return view.equals(obj);
}

@Override
public Object instantiateItem (View views, int position)
{
    View v = pages.get(position);
    ((ViewPager) views).addView(v, 0);

    return v;
}

@Override
public void destroyItem(View views, int position, Object view)
{
    ((ViewPager) views).removeView((View) view);
}

@Override
public void finishUpdate(View view)
{       
}

@Override
public void restoreState(Parcelable arg0, ClassLoader arg1)
{
}

@Override
public Parcelable saveState()
{
    return null;
}

@Override
public void startUpdate(View view)
{

}

活动:

    List<View> pages = new ArrayList<View>();
    View page = inflater.inflate(R.layout.page, null);
    TextView textView = (TextView) page.findViewById(R.id.text_view);
    textView.setText("Page 1"); // first page
    pages.add(page);


    page = new surfaceControl(this); // second page with some modul
    pages.add(page);


    slide pageAdapter = new slide(pages); 
    ViewPager viewPager = new ViewPager(this);
    viewPager.setAdapter(pageAdapter);
    viewPager.setCurrentItem(0);

0 个答案:

没有答案