-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
Marcin Nowrot edited this page Jun 17, 2013
·
4 revisions
- Set up both
EcoGallery
andEcoGalleryIndicator
as dependencies to your app - Include the
EcoGalleryIndicator
widget in your view. This should usually be placed adjacent to theEcoGallery
it indicates.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<us.feras.ecogallery.EcoGallery
android:id="@+id/images"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:unselectedAlpha="1" />
<!-- Size and color are optional - you may leave them out. The default values are given below. -->
<pl.mnowrot.ecogalleryindicator.EcoGalleryIndicator
android:id="@+id/images_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/vertical_padding_standard"
android:layout_gravity="center"
app:color="@android:color/background_light"
app:size="10dp" />
</LinearLayout>
- In your onCreate method (or onCreateView for a fragment), first inflate the parent view and bind the indicator to the
EcoGallery
like this:
private void setupGalleryView(View parentView) {
EcoGallery gallery = (EcoGallery) parentView.findViewById(R.id.images);
Resources resources = getResources();
// GallerySpinnerAdapter implements SpinnerAdapter (see EcoGallery docs for details)
GallerySpinnerAdapter adapter = new GallerySpinnerAdapter(gallery.getContext(),
resources.getDrawable(R.drawable.img0), resources.getDrawable(R.drawable.img1),
resources.getDrawable(R.drawable.img2));
gallery.setAdapter(adapter);
// create and bind the indicator
EcoGalleryIndicator galleryIndicator = (EcoGalleryIndicator) parentView
.findViewById(R.id.images_indicator);
galleryIndicator.setEcoGallery(gallery);
// optionally set up size and color of the indicator (better do it in the XML - see above)
galleryIndicator.setSize(resources.getDimensionPixelSize(R.dimen.10dp_size));
galleryIndicator.setColor(resources.getColor(android.R.color.background_light));
// optionally if you use an OnItemSelectedListener with the EcoGallery you need to set it
// on the indicator rather than on the EcoGallery directly
galleryIndicator.setOnItemSelectedListener(mOnItemSelectedListener);
}