0

ギャラリーから写真を取得し、それらを動的な ImageViews に表示する必要があるアプリケーションに取り組んでいます。これで成功しましたが、ギャラリーから取得した写真でスライドショーを作成する必要があります。これどうやってするの?

これが私のコードです:

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