Android Beginner Image Gallery Example
Tutorial using PlaceHolderView
This example demonstrate creation of a list of images with animation using PlaceHolderView. For the sake of this example we will be placing our images in the drawable folder.
Note: After exploring this example I will strongly recommend going through next advanced and complete example listed here.
Reference to PlaceHolderView can be found here
Lets Begin:
Step 1:
Create a project in the Android Studios and add dependency in app’s build.gradle
Step 2:
Create Activity XML layout res/layout/activity_main.xml
Step 3:
Create gallery image item view res/layout/gallery_item.xml
Step 4:
Create GalleryItem.class
Notes:
- @NonReusable is annotation in PlaceHolderView, to be used in cases where we want to release all the resources and references if removed from the list and won’t use the same object in addView() method in PlaceHolderView.
- @layout is used to bind the layout with this class
- @View is used to bind the views in this layout we want to refer to
- @Resolve is used to operate on the view references obtained from @View, in short if we want to define any operation on the view it should be put in a method and annotated with @Resolve
- @Animate() is used to assign defined animations in the Animation class
Step 5:
Create the MainActivity.class.
Get the reference to the PlaceHolderView and then add views to this using addView method.
Note:
If we need a grid of 2 rows then use Builder class.
mGalleryView.getBuilder().setLayoutManager(new GridLayoutManager(this.getApplicationContext(), 2));