Saludos, mira checate este codigo que tengo te pone las fotos como si fuera una galeria.
Código Javascript
:
Ver originalpackage com.AndroidPhotoBar;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class AndroidPhotoBarActivity extends Activity {
ArrayList<ImageItem> arrayImageItem;
MyAdapter myAdapter;
public class ImageItem {
Bitmap bitmapImage;
ImageItem(){
//To simplify, we use a default image here
bitmapImage = BitmapFactory.decodeResource(
AndroidPhotoBarActivity.this.getResources(), R.drawable.icon);
}
public Bitmap getImage(){
return bitmapImage;
}
}
Gallery myPhotoBar;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myPhotoBar = (Gallery)findViewById(R.id.photobar);
myAdapter = new MyAdapter(this); //init myAdapter without ImageItem
//insert dummy ImageItem into myAdapter
insertDummyImageItem(2);
myPhotoBar.setAdapter(myAdapter);
//insert dummy ImageItem into myAdapter in Run time
insertDummyImageItem(3);
myAdapter.notifyDataSetChanged();
}
private void insertDummyImageItem(int cnt){
//Insert dummy ImageItem into myAdapter
for(int i = 0; i < cnt; i++){
myAdapter.addImageItem(new ImageItem());
}
}
public class MyAdapter extends BaseAdapter {
Context context;
ArrayList<ImageItem> _arrayImageItem;
MyAdapter(Context c){
context = c;
_arrayImageItem = new ArrayList<ImageItem>();
}
public void addImageItem(ImageItem item){
_arrayImageItem.add(item);
}
public int getCount() {
// TODO Auto-generated method stub
return _arrayImageItem.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return _arrayImageItem.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView imageView;
imageView = new ImageView(context);
imageView.setLayoutParams(new Gallery.LayoutParams(150, 150));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageBitmap(_arrayImageItem.get(position).getImage());
return imageView;
}
}
}
Y el main.xml
Código Javascript
:
Ver original<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Gallery
android:id="@+id/photobar"
android:layout_width="fill_parent"
android:layout_height="150dp"
/>
</LinearLayout>