Buongiorno a tutti , devo andare a visualizzare una serie di immagini in una gallery ed il codice che ho utilizzato è questo:
1public class ViewImmaginiA extends Activity {
2/** Called when the activity is first created. */
3
4public void onCreate(Bundle icicle) {
5super.onCreate(icicle);
6setContentView(R.layout.immagini2);
7
8/* Find the gallery defined in the main.xml
9* Apply a new (custom) ImageAdapter to it. */
10((Gallery) findViewById(R.id.gallery))
11.setAdapter(new ImageAdapter(this));
12}
13
14public class ImageAdapter extends BaseAdapter {
15/** The parent context */
16private Context myContext;
17
18/** URL-Strings to some remote images. */
19private String[] myRemoteImages = {
20//"/sdcard/Multimedia/Immagini/image_LARGE_2.unknown",
21"/sdcard/Multimedia/Immagini/image_LARGE_10.unknown",
22"/sdcard/Multimedia/Immagini/image_LARGE_11.unknown",
23"/sdcard/Multimedia/Immagini/image_LARGE_12.unknown",
24"/sdcard/Multimedia/Immagini/image_LARGE_13.unknown",
25"/sdcard/Multimedia/Immagini/image_LARGE_14.unknown",
26"/sdcard/Multimedia/Immagini/image_LARGE_15.unknown",
27};
28
29/** Simple Constructor saving the 'parent' context. */
30public ImageAdapter(Context c) { this.myContext = c; }
31
32/** Returns the amount of images we have defined. */
33public int getCount() { return this.myRemoteImages.length; }
34
35/* Use the array-Positions as unique IDs */
36public Object getItem(int position) { return position; }
37public long getItemId(int position) { return position; }
38
39/** Returns a new ImageView to
40* be displayed, depending on
41* the position passed. */
42public View getView(int position, View convertView, ViewGroup parent) {
43ImageView i = new ImageView(this.myContext);
44//ImageView jpgView = (ImageView)findViewById(R.id.jpgview);
45String myJpgPath;
46
47myJpgPath = myRemoteImages[position];
48//myJpgPath = "/sdcard/Multimedia/Immagini/image_LARGE_3.unknown";
49BitmapFactory.Options options = new BitmapFactory.Options();
50options.inSampleSize = 2;
51Bitmap bm1 = BitmapFactory.decodeFile(myJpgPath, options);
52//jpgView.setImageBitmap(bm1);
53i.setImageBitmap(bm1);
54
55/* Image should be scaled as width/height are set. */
56i.setScaleType(ImageView.ScaleType.FIT_CENTER);
57/* Set the Width/Height of the ImageView. */
58i.setLayoutParams(new Gallery.LayoutParams(300, 250));
59return i;
60}
61
62/** Returns the size (0.0f to 1.0f) of the views
63* depending on the 'offset' to the center. */
64public float getScale(boolean focused, int offset) {
65/* Formula: 1 / (2 ^ offset) */
66return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset)));
67}
68}
69}
70
71
Ma il risultato è questo:
Mentre io pensavo di fare per ogni schermata un'immagine che faccio scorrere...così invece sembra che vengono sovrapposte.
Oppure una cosa del genere dite che sia adatta??
Grazie a tutti per le risposte!! ;-)