MainActivity.java
public class MainActivity extends Activity { ViewPager viewpager; // private View view1, view2, view3; private List<View> viewList;//view数组 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // viewpager = (ViewPager) findViewById(R.id.viewpager); //\\ LayoutInflater inflater=getLayoutInflater(); view1 = inflater.inflate(R.layout.page1, null); view2 = inflater.inflate(R.layout.page2,null); view3 = inflater.inflate(R.layout.page3, null); // viewList = new ArrayList<View>();// 将要分页显示的View装入数组中 viewList.add(view1); viewList.add(view2); viewList.add(view3); //\\ PagerAdapter pagerAdapter = new PagerAdapter() { @Override public boolean isViewFromObject(View arg0, Object arg1) { // TODO Auto-generated method stub return arg0 == arg1; } @Override public int getCount() { // TODO Auto-generated method stub return viewList.size(); } @Override public void destroyItem(ViewGroup container, int position, Object object) { // TODO Auto-generated method stub container.removeView(viewList.get(position)); } @Override public Object instantiateItem(ViewGroup container, int position) { // TODO Auto-generated method stub container.addView(viewList.get(position)); return viewList.get(position); } }; viewpager.setAdapter(pagerAdapter); } //====================================== }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v4.view.ViewPager> </LinearLayout>
page1.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:background="#ff00ff" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:text="aaaaaaaaaa" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout>
page2.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:background="#ff0000" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:text="bbbbbbbbb" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout>
page3.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:background="#0000ff" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:text="cccccccccc" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout>
相关推荐
Android-DragDismissActivity:滑动取消Activity
Shuffle - Android易于使用滑动视图
android-整体UI设计滑动导航栏滚动页面.zip
在 Android端app上,自定义View,仿一个斗鱼web端滑动验证码
Swipper - Android库可滑动手势来控制音量,亮度和搜索
Android-ListView监听上下滑动.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
android导航菜单横向左右滑动并和下方的控件实现联动
SlidePageView组件实现的仿微信上次使用时引导页面demo, 还有SlidePageView实现的自定义的等宽和不等宽显示单元页面的demo 详情可以看我的博客http://blog.csdn.net/swadair/article/details/7529159
原生js拖拽功能制作滑动条实例代码 拖拽属于前端常见的功能,很多效果都会用到js的拖拽功能。...--滑动条--> <div class="bar_into"></div><!--滑动痕迹--> </div> <div class="bar_drag"><!--滑块--> <div
android-整体UI设计(滑动导航栏+滚动页面)
支持整页滑动的 RecyclerView
android-swipelistview-支持左右滑动.rar
博客《ViewPager 详解(四)----自主实现滑动指示条》对应源码,博客地址:http://blog.csdn.net/harvic880925/article/details/38557517
Android 使用android-support-v4.jar类库实现QQ向左滑动删除功能,源代码包中附有android-support-v4.jar类库,其它android应用需要此类库时,也可下载本源码。 制作方法详见源代码文件,操作方法和QQ侧滑删除一样...
将此项目添加到需要实现此功能的项目中 项目-->properties-->Android-->Library-->Add
Android高级应用源码-android-swipelistview-支持左右滑动.zip
很多朋友对RollNavigationBar+SlidePageView如何设计业务界面感到疑惑,今天我专门写...了解详情可以看我的博客《android-整体UI设计-(滑动导航栏+滚动页面)》http://blog.csdn.net/swadair/article/details/7551609
android-swipelistview-支持左右滑动.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
android-整体UI设计(滑动导航栏 滚动页面)
SwitchButton 炫酷的滑动开关