Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/09/2011, 11:44
Avatar de zero_master
zero_master
 
Fecha de Ingreso: junio-2011
Ubicación: Leon, Gto
Mensajes: 290
Antigüedad: 13 años, 5 meses
Puntos: 74
Respuesta: Item para mostrar imagenes con transicion

Saludos, mira checate este codigo que tengo te pone las fotos como si fuera una galeria.
Código Javascript:
Ver original
  1. package com.AndroidPhotoBar;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import android.app.Activity;
  6. import android.content.Context;
  7. import android.graphics.Bitmap;
  8. import android.graphics.BitmapFactory;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.BaseAdapter;
  13. import android.widget.Gallery;
  14. import android.widget.ImageView;
  15.  
  16. public class AndroidPhotoBarActivity extends Activity {
  17.  
  18. ArrayList<ImageItem> arrayImageItem;
  19. MyAdapter myAdapter;
  20.  
  21.   public class ImageItem {
  22.  
  23.    Bitmap bitmapImage;
  24.  
  25.    ImageItem(){
  26.     //To simplify, we use a default image here
  27.     bitmapImage = BitmapFactory.decodeResource(
  28.       AndroidPhotoBarActivity.this.getResources(), R.drawable.icon);
  29.    }
  30.  
  31.    public Bitmap getImage(){
  32.     return bitmapImage;
  33.    }
  34.  
  35. }
  36.  
  37.   Gallery myPhotoBar;
  38.  
  39. /** Called when the activity is first created. */
  40.   @Override
  41.   public void onCreate(Bundle savedInstanceState) {
  42.       super.onCreate(savedInstanceState);
  43.       setContentView(R.layout.main);
  44.       myPhotoBar = (Gallery)findViewById(R.id.photobar);
  45.      
  46.       myAdapter = new MyAdapter(this); //init myAdapter without ImageItem
  47.      
  48.       //insert dummy ImageItem into myAdapter
  49.       insertDummyImageItem(2);
  50.       myPhotoBar.setAdapter(myAdapter);
  51.      
  52.       //insert dummy ImageItem into myAdapter in Run time
  53.       insertDummyImageItem(3);
  54.       myAdapter.notifyDataSetChanged();
  55.  
  56.   }
  57.  
  58.   private void insertDummyImageItem(int cnt){
  59.  
  60.    //Insert dummy ImageItem into myAdapter
  61.    for(int i = 0; i < cnt; i++){
  62.     myAdapter.addImageItem(new ImageItem());
  63.    }
  64.  
  65.   }
  66.  
  67.   public class MyAdapter extends BaseAdapter {
  68.  
  69.    Context context;
  70.    ArrayList<ImageItem> _arrayImageItem;
  71.  
  72.    MyAdapter(Context c){
  73.     context = c;
  74.     _arrayImageItem = new ArrayList<ImageItem>();
  75.    }
  76.  
  77.    public void addImageItem(ImageItem item){
  78.     _arrayImageItem.add(item);
  79.    }
  80.  
  81. public int getCount() {
  82.  // TODO Auto-generated method stub
  83.  return _arrayImageItem.size();
  84. }
  85.  
  86. public Object getItem(int position) {
  87.  // TODO Auto-generated method stub
  88.  return _arrayImageItem.get(position);
  89. }
  90.  
  91. public long getItemId(int position) {
  92.  // TODO Auto-generated method stub
  93.  return position;
  94. }
  95.  
  96. public View getView(int position, View convertView, ViewGroup parent) {
  97.  // TODO Auto-generated method stub
  98.  ImageView imageView;
  99.  imageView = new ImageView(context);
  100.  
  101.  imageView.setLayoutParams(new Gallery.LayoutParams(150, 150));
  102.  imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
  103.  imageView.setImageBitmap(_arrayImageItem.get(position).getImage());
  104.  
  105.  return imageView;
  106. }
  107.  
  108. }
  109. }

Y el main.xml

Código Javascript:
Ver original
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.   android:orientation="vertical"
  4.   android:layout_width="fill_parent"
  5.   android:layout_height="fill_parent"
  6.   >
  7. <TextView
  8.   android:layout_width="fill_parent"
  9.   android:layout_height="wrap_content"
  10.   android:text="@string/hello"
  11.   />
  12. <Gallery
  13. android:id="@+id/photobar"
  14. android:layout_width="fill_parent"
  15. android:layout_height="150dp"
  16. />
  17. </LinearLayout>