Guest User

Untitled

a guest
Apr 27th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. package org.yaaic.deckster;
  2.  
  3. import android.content.Context;
  4. import android.content.res.TypedArray;
  5. import android.util.Log;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.BaseAdapter;
  10. import android.widget.Gallery;
  11. import android.widget.TextView;
  12.  
  13. public class DecksterAdapter extends BaseAdapter
  14. {
  15. private int width;
  16. private int height;
  17.  
  18. public DecksterAdapter(int width, int height)
  19. {
  20. this.width = width;
  21. this.height = height;
  22.  
  23. Log.d("foo", width + "x" + height);
  24. }
  25.  
  26. public int getCount()
  27. {
  28. return 7;
  29. }
  30.  
  31. public Object getItem(int position)
  32. {
  33. return position;
  34. }
  35.  
  36. public long getItemId(int position)
  37. {
  38. return position;
  39. }
  40.  
  41. private int[] colors = {
  42. 0xfffce94f,
  43. 0xfffcaf3e,
  44. 0xffe9b96e,
  45. 0xff8ae234,
  46. 0xff729fcf,
  47. 0xffad7fa8,
  48. 0xffef2929,
  49. };
  50.  
  51. public View getView(int position, View convertView, ViewGroup parent)
  52. {
  53. LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  54. View v = inflater.inflate(R.layout.view, null);
  55.  
  56. float fw = (float) width;
  57. float fh = (float) height;
  58.  
  59. float vwf = fw / 100 * 80;
  60. float vhf = fh / 100 * 80;
  61.  
  62. int w = (int) vwf;
  63. int h = (int) vhf;
  64.  
  65. TextView tv = (TextView) v.findViewById(R.id.foo);
  66. tv.setTextColor(0xff000000);
  67. tv.setText("T" + position);
  68. tv.setBackgroundColor(colors[position]);
  69.  
  70. v.setLayoutParams(new Gallery.LayoutParams(w, h));
  71.  
  72. return v;
  73. }
  74.  
  75. }
Add Comment
Please, Sign In to add comment