Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. @Override
  2. public void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. requestWindowFeature(Window.FEATURE_NO_TITLE);
  5. setContentView(R.layout.algal);
  6.  
  7.  
  8.  
  9.  
  10. mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
  11. mSwitcher.setFactory(this);
  12. mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
  13. android.R.anim.fade_in));
  14. mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
  15. android.R.anim.fade_out));
  16.  
  17. @SuppressWarnings("deprecation")
  18. Gallery g = (Gallery) findViewById(R.id.gallery);
  19. g.setAdapter(new ImageAdapter(this));
  20. g.setOnItemSelectedListener(this);
  21. }
  22.  
  23. public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
  24. mSwitcher.setImageResource(mImageIds[position]);
  25. }
  26.  
  27. public void onNothingSelected(AdapterView<?> parent) {
  28. }
  29.  
  30.  
  31. @SuppressWarnings("deprecation")
  32. public View makeView() {
  33. ImageView i = new ImageView(this);
  34. i.setBackgroundResource(R.drawable.back);
  35. i.setScaleType(ImageView.ScaleType.FIT_CENTER);
  36. i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,
  37. LayoutParams.MATCH_PARENT));
  38. return i;
  39. }
  40.  
  41. private ImageSwitcher mSwitcher;
  42.  
  43. public class ImageAdapter extends BaseAdapter {
  44. public ImageAdapter(Context c) {
  45. mContext = c;
  46. }
  47.  
  48. public int getCount() {
  49. return mThumbIds.length;
  50. }
  51.  
  52. public Object getItem(int position) {
  53. return position;
  54. }
  55.  
  56. public long getItemId(int position) {
  57. return position;
  58. }
  59.  
  60. @SuppressWarnings("deprecation")
  61. public View getView(int position, View convertView, ViewGroup parent) {
  62. ImageView i = new ImageView(mContext);
  63.  
  64. i.setImageResource(mThumbIds[position]);
  65. i.setAdjustViewBounds(true);
  66. i.setLayoutParams(new Gallery.LayoutParams(
  67. LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  68.  
  69. return i;
  70. }
  71.  
  72. private Context mContext;
  73.  
  74. }
  75.  
  76. private Integer[] mThumbIds = {
  77.  
  78. R.drawable.a, R.drawable.bb, R.drawable.cc, R.drawable.dd, R.drawable.ee, R.drawable.ff, R.drawable.gg, R.drawable.hh, R.drawable.ii, R.drawable.jj,
  79. R.drawable.kk, R.drawable.ll, R.drawable.mm, R.drawable.nn, R.drawable.oo, R.drawable.pp, R.drawable.qq, R.drawable.rr, R.drawable.ss, R.drawable.tt,
  80. R.drawable.uu, R.drawable.vv, R.drawable.xx, R.drawable.yy, R.drawable.zz};
  81.  
  82. private Integer[] mImageIds = {
  83. R.drawable.a, R.drawable.bb, R.drawable.cc, R.drawable.dd, R.drawable.ee, R.drawable.ff, R.drawable.gg, R.drawable.hh, R.drawable.ii, R.drawable.jj,
  84. R.drawable.kk, R.drawable.ll, R.drawable.mm, R.drawable.nn, R.drawable.oo, R.drawable.pp, R.drawable.qq, R.drawable.rr, R.drawable.ss, R.drawable.tt,
  85. R.drawable.uu, R.drawable.vv, R.drawable.xx, R.drawable.yy, R.drawable.zz};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement