1

I use ViewPager to switch several views.

public class MainA extends ActivityGroup {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ViewPager pager = (ViewPager)findViewById(R.id.viewpager);
    ViewPager pager = (ViewPager)findViewById(R.id.viewpager);
    View view1 = inflater.inflate(R.layout.viewa,null );
    View view2 = inflater.inflate(R.layout.viewp, null);
    ImageView imageView = new ImageView(getApplicationContext());
    imageView.setImageResource(R.drawable.ic_action_search);
    views.add(imageView);
    views.add(view1);
    views.add(view2);}}

ViewPager will set imageView as first view. When I turn left,there is no view. When I turn right , view1 will come out. Now I have one question. I want to set view1 as first view. When I turn left, imageView will come out. When I turn right, view2 will come out. How to do that ???

4

1 回答 1

0

如果您有多个视图,那么最好使用 PagerAdapter 添加所有这些视图。然后像这样设置第一个视图选择

 ViewPagerAdapter adapter = new ViewPagerAdapter(this, imageArra);
 ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
 myPager.setAdapter(adapter);
 myPager.setCurrentItem(0);`
于 2012-10-10T04:37:45.643 回答