final android.support.v4.view.ViewPager viewPager = new android.support.v4.view.ViewPager(this);
viewPager.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
viewPager.setBackgroundColor(Color.BLACK);
MyPagerAdapter adapter = new MyPagerAdapter();
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(0);
linear1.addView(viewPager);
}
private class MyPagerAdapter extends android.support.v4.view.PagerAdapter {
public int getCount() {
return 4;
}
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0:
resId = R.layout.left;
break;
case 1:
resId = R.layout.farleft;
break;
case 2:
resId = R.layout.middle;
break;
case 3:
resId = R.layout.right;
break;
}
View view = inflater.inflate(resId, null);
((android.support.v4.view.ViewPager)collection).addView(view, 0);
return view;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((android.support.v4.view.ViewPager) arg0).removeView((View) arg2);
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
@Override
public Parcelable saveState() {
return null;
}
Nothing.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.