0

I am working on application in which I need to fetch pictures from gallery and display those into dynamic ImageViews. I am successful doing this, but now I have to create a slide show with the pictures fetched from gallery. How can I do this?

Here is my code:

LinearLayout lLayout;
Bitmap yourSelectedImage;
int flag=1;
ImageView slidingimage;
int imageId=1;
int imageindex=1;

int i=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    createLayout();


}

public void createLayout(){

    LinearLayout parentLayout = (LinearLayout)findViewById(R.id.Playout);
       lLayout = new LinearLayout(this);
        lLayout.setOrientation(LinearLayout.HORIZONTAL);


        LinearLayout.LayoutParams myLayoutParams = new LinearLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

        myLayoutParams.leftMargin = 0;
        //myLayoutParams.topMargin = 50 * i;
        myLayoutParams.width = 480;
        myLayoutParams.height = 150;

        lLayout.setLayoutParams(myLayoutParams);

        parentLayout.addView(lLayout);


        btn1 = new Button(this); 
        btn1.setBackgroundResource(R.drawable.add);
        //btn1.setId(i);



        LinearLayout.LayoutParams rel_btn = new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

            /*rel_btn.leftMargin = 150;
            rel_btn.topMargin = myYPosition;*/
            rel_btn.width = 160;
            rel_btn.height = 150;

            btn1.setLayoutParams(rel_btn);

            lLayout.addView(btn1);
            btn1.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    // Perform action on click   

                    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                    photoPickerIntent.setType("image/*");
                    startActivityForResult(photoPickerIntent, 1);


                }
            });


}

protected void onActivityResult(int requestCode, int resultCode, 
           Intent imageReturnedIntent) {
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

        switch(requestCode) { 
        case 1:
            if(resultCode == RESULT_OK){  
                Uri selectedImage = imageReturnedIntent.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};

                Cursor cursor = getContentResolver().query(
                                   selectedImage, filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String filePath = cursor.getString(columnIndex);
                cursor.close();
                yourSelectedImage = BitmapFactory.decodeFile(filePath);

                ImageView img = new ImageView(this);
                LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(160,150);
                img.setLayoutParams(parms);
                img.setId(imageId);

                imageId++;
                img.setImageBitmap(yourSelectedImage);
                lLayout.addView(img, 0);
                flag++;

                if(flag>3){

                    btn1.setVisibility(View.INVISIBLE);
                    createLayout();
                    flag=1;
                }
            }
        }
    }
4

1 回答 1

0

您可以创建所有已获取图像的列表,然后将它们显示在图像视图或列表视图中,无论您想要什么......

 ArrayList<Bitmap/or drawable (you choose)> variable1=null;

create a loop
for(till all images are fetched............)
{

Bitmap/Drawable variable2=new Bitmap/Drawable();
variable2=your image from gallery;
variable1.add(variable2);
}

现在已获取所有图像并包含在列表中(变量 1).... 1 逐 1 显示它们,或者您想显示它们............

于 2013-09-27T22:12:26.510 回答