1. 创建activity
public class CollectionDemoActivity extends FragmentActivity {
// When requested, this adapter returns a DemoObjectFragment,
// representing an object in the collection.
// 分页的adapter
DemoCollectionPagerAdapter mDemoCollectionPagerAdapter;
// 使用ViewPager来控制分页
ViewPager mViewPager;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_collection_demo);
// ViewPager and its adapters use support library
// fragments, so use getSupportFragmentManager.
mDemoCollectionPagerAdapter =
new DemoCollectionPagerAdapter(
getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mDemoCollectionPagerAdapter);
}
}
2. 创建分页的adapter
public class DemoCollectionPagerAdapter extends
FragmentStatePagerAdapter {
public DemoCollectionPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override // 通过此方法创建每个页的fragmet
public Fragment getItem(int i) {
Fragment fragment = new DemoObjectFragment();
Bundle args = new Bundle();
// Our object is just an integer :-P
args.putInt(DemoObjectFragment.ARG_OBJECT, i + 1);
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
return 100;
}
@Override
public CharSequence getPageTitle(int position) {
return "OBJECT " + (position + 1);
}
}
3. 创建每个页的fragment
public static class DemoObjectFragment extends Fragment {
public static final String ARG_OBJECT = "object";
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
// The last two arguments ensure LayoutParams are inflated
// properly.
View rootView = inflater.inflate(
R.layout.fragment_collection_object, container, false);
Bundle args = getArguments();
((TextView) rootView.findViewById(android.R.id.text1)).setText(
Integer.toString(args.getInt(ARG_OBJECT)));
return rootView;
}
}
4. xml配置
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:textColor="#fff"
android:paddingTop="4dp"
android:paddingBottom="4dp" />
</android.support.v4.view.ViewPager>
分享到:
相关推荐
android-swipe-views-tabs.7z
本篇文章主要介绍了基于vue实现swipe分页组件实例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
元宵节swipe节日案例
用户用手指上下划动页面,从而切换页面。UIScrollView 上拉/下拉刷新。 注意:请在Mac下解压使用
swipe插件的使用
应用uni-swipe-action组件实现列表项左划操作。 真正做到开箱即用。
来源:Licence:MIT平台:iOS设备:iPhone / iPad作者:Peter Boctor 用户用手指上下划动页面,从而切换页面。UIScrollView 上拉/下拉刷新 Code4App编译测试,适用环境:Xcode 4.3, iOS 5.0。
而让我眼前一亮的是微格,它的操作方式可以看成是navigation+swipe,上手感觉很顺畅,手指的操作也很自然,这让我想起了前段时间诺基亚发布的N9,N9强调的一种用户体验就是swipe,一种最自然的手势。 自己也在...
前端项目-swipejs,Swipe is the most accurate touch slider
swipe实现轮播图的运用swipe是一个轻量级的移动滑动组件,它可以支持精确的触滑移动操作,能解决移动端对滑动的需求。
swipe多种手机触屏滑动效果
liquid_swipe_flutter,基于拍打的液体滑动----------------------,博客附件,效果请查看博客相对应项目。
滑动页面 有关更多信息,请参见。 去做 提高页面滚动稳定性 提高页面滚动性能 提高页面之间滑动的性能(通过重复使用页面?) ... <swipe>I am page 0<swipe> <swipe>I am page 1<swipe> <s
react-swipe - 将Swipe.js当作一个React组件
Swipe-Deck, Android的Tinder风格Swipeable面板视图 swipe Android的Tinder风格Swipeable面板视图注释我已经经将这里项目从地面编写为 SwipeDeck2,并且在这里可以用: https://github.com/aaronbond/SwipeDeck2我最
这是本文中关于在没有任何外部库的情况下使用recyclerview创建swipe菜单的源代码。
Swipe-to-Select-GridView ,Swipe-to-Select-GridView 是一个基于 UICollectionView 的 ...
swipe, 使用触摸支持( 用于图像旋转器,动态内容等) 滑动组件 滑动使用触摸屏或者任何其他内容触摸组件的滑动组件。 在你的浏览器或者设备上试用演示插件。安装$ component install component/swipe事件showing ( i...
android recyclerView 的item拖拽,item的交换,测滑删除等。