这是从github上的一个开源项目Android-ViewPagerIndicator上抽取出来的一个小的Demo.先看效果图:
实现代码首先是布局文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:padding="20dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="bottom"/>
</FrameLayout>
主窗体代码:
public class MyActivity extends BaseSampleActivity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mIndicator = (CirclePageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
}
}
源码下载地址: http://download.youkuaiyun.com/detail/panjq882288/5800725