Friday, June 21, 2013

Android 1: Lesson 13

Android 1: Lesson 13: Image Swiper Part 2


INTRODUCTION
In this lesson you will be Importing a few more pictures into your app, and you’ll be creating an Activity that allows you to swipe in between them
LESSON OBJECTIVES
By the end of this lesson, you will be able to:
1. Swipe in between a few images
2. Add another Activity to the menu
3. Completely understand the manifest
LEARNING SEQUENCE



Required Reading
Read the following:
Introduction To Development Environment
·        Eclipse
·        Android
·        Considerations for beginning programming.
Resources
View the following:
1.      Eclipse
2.     Android Development
Assignments
  1. Above the ‘return null’ type ‘ImageView i = new ImageView(this);’ import it
  2. Enter ‘i.setBackgroundColor(0xff000000);’ this should match up with what you had down in your xml
  3. Enter ‘i.setScaleType(ImageView.ScaleType.FIT_CENTER);’ this is how the picture fits on screen.
  4. Enter ‘i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));’ go to the top and import ‘android.widget.Gallery.LayoutParams’
  5. Change ‘null’ to ‘i’
  6. Under the View ending brackets type ‘private ImageSwitcher mSwitcher;’
  7. Enter ‘public class ImageAdapter extends BaseAdapter’ You are extending another activity within this activity. Import the BaseAdapter, and add unimplemented methods of ImageAdapter
  8. Enter ‘public ImageAdapter(Context c) {
  9. Enter ‘mContext = c;’
  10. When you added the implemented methods of ImageAdapter, it generated some code. For the ‘getCount’ change 0 to ‘mSpaceIds.length’
  11. For ‘getItem’ change null to ‘position’
  12. For ‘getItemId’ change 0 to ‘position’
  13. Move down to the ‘getView; Above the ‘return’ type ‘ImageView i = new ImageView(mContext);’
  14. Enter ‘i.setImageResource(mSpaceIds[position]);’
  15. Enter ‘i.setAdjustViewBounds(true);’
  16. Enter ‘i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));’
  17. Enter ‘i.setBackgroundResource(R.drawable.testbackground);’ ‘testbackground’ should be whatever you named that picture that is in your drawable folder from the Logo lesson.
  18. Change null to i
  19. Under the ‘getView’ ending brackets, type ‘private Context mContext;’ import the context
  20. Under the ending brackets of that type ‘private Integer[] mSpaceIds = {R.drawable.pic1, R.drawable.pic2’
  21. Enter ‘private Integer[] mImageIds = {R.drawable.pic1, R.drawable.pic2’ for pic1 and 2, type out the names of the pictures you put in your app folders.
  22. Export and see how it works!

No comments:

Post a Comment