Reputation: 1550
I am trying to implement the view pager indicator. This is the code in my onCreate method. I have followed the instructions on this page to implement the library and yet nothing is being displayed as I flip through the pages.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.item_view_tablet);
Bitmap backgroundPic = mainPicBitmap("image_uri_from_db");
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
Drawable backgroundDrawable = new BitmapDrawable(getResources(),backgroundPic);
mViewPager.setBackground(backgroundDrawable);
mViewPager.setAdapter(mSectionsPagerAdapter);
CirclePageIndicator titleIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
titleIndicator.setViewPager(mViewPager);
db.close();
}
This part CirclePageIndicator titleIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
titleIndicator.setViewPager(mViewPager);
is supposed to make it work, but nothing displays. I checked the sample application and it is used the same way. What am I doing wrong? Any suggestions appreciated
My layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="400sp"
android:orientation="vertical" xmlns:app="http://schemas.android.com/apk/res/co.za.datasolve.acollect">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ViewCategoryTabletActivity" >
</android.support.v4.view.ViewPager>
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:padding="10dip"
android:layout_height="20sp"
android:layout_width="fill_parent"
/>
</LinearLayout>
Upvotes: 0
Views: 2180
Reputation: 87064
You use a vertical LinearLayout
and you've set the height of the ViewPager
(the first child of the LinearLayout
) to match_parent
which will make it take the whole height of the parent pushing the indicator outside. Try something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="400sp"
android:orientation="vertical" xmlns:app="http://schemas.android.com/apk/res/co.za.datasolve.acollect">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:context=".ViewCategoryTabletActivity" >
</android.support.v4.view.ViewPager>
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:padding="10dip"
android:layout_height="20dp"
android:layout_width="fill_parent"
/>
</LinearLayout>
Upvotes: 4