CERCA
PER MODELLO
FullScreen Chatbox! :)

Utente del giorno: carotix con ben 1 Thanks ricevuti nelle ultime 24 ore
Utente della settimana: megthebest con ben 7 Thanks ricevuti negli ultimi sette giorni
Utente del mese: megthebest con ben 20 Thanks ricevuti nell'ultimo mese

Visualizzazione dei risultati da 1 a 1 su 1
Discussione:

Visualizzazione immagini in gallery

Se questa discussione ti è stata utile, ti preghiamo di lasciare un messaggio di feedback in modo che possa essere preziosa in futuro anche per altri utenti come te!
  1. #1
    Baby Droid


    Registrato dal
    Jan 2011
    Messaggi
    30

    Ringraziamenti
    0
    Ringraziato 0 volte in 0 Posts
    Predefinito

    Visualizzazione immagini in gallery

    Buongiorno a tutti , devo andare a visualizzare una serie di immagini in una gallery ed il codice che ho utilizzato è questo:

     
    1
    public class ViewImmaginiA extends Activity {
    2
            /** Called when the activity is first created. */
    3
            @Override
    4
            public void onCreate(Bundle icicle) {
    5
                super.onCreate(icicle);
    6
                setContentView(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
         
    14
            public class ImageAdapter extends BaseAdapter {
    15
                /** The parent context */
    16
                private Context myContext;
    17
         
    18
                /** URL-Strings to some remote images. */
    19
                private 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. */
    30
                public ImageAdapter(Context c) { this.myContext = c; }
    31
         
    32
                /** Returns the amount of images we have defined. */
    33
                public int getCount() { return this.myRemoteImages.length; }
    34
         
    35
                /* Use the array-Positions as unique IDs */
    36
                public Object getItem(int position) { return position; }
    37
                public long getItemId(int position) { return position; }
    38
         
    39
                /** Returns a new ImageView to
    40
                 * be displayed, depending on
    41
                 * the position passed. */
    42
                public View getView(int position, View convertView, ViewGroup parent) {
    43
                    ImageView i = new ImageView(this.myContext);
    44
                    //ImageView jpgView = (ImageView)findViewById(R.id.jpgview);
    45
                    String myJpgPath;
    46
    47
                    myJpgPath = myRemoteImages[position];
    48
                    //myJpgPath = "/sdcard/Multimedia/Immagini/image_LARGE_3.unknown";
    49
                    BitmapFactory.Options options = new BitmapFactory.Options();
    50
                    options.inSampleSize = 2;
    51
                    Bitmap bm1 = BitmapFactory.decodeFile(myJpgPath, options);
    52
                    //jpgView.setImageBitmap(bm1); 
    53
                    i.setImageBitmap(bm1);
    54
    55
                    /* Image should be scaled as width/height are set. */
    56
                    i.setScaleType(ImageView.ScaleType.FIT_CENTER);
    57
                    /* Set the Width/Height of the ImageView. */
    58
                    i.setLayoutParams(new Gallery.LayoutParams(300, 250));
    59
                    return i;
    60
                }
    61
         
    62
                /** Returns the size (0.0f to 1.0f) of the views
    63
                 * depending on the 'offset' to the center. */
    64
                public float getScale(boolean focused, int offset) {
    65
                        /* Formula: 1 / (2 ^ offset) */
    66
                    return 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!! ;-)

  2.  

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire risposte
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Torna su
Privacy Policy