0

こんにちは、値を変更してレイアウトを保存するために反復するループがあります.xmlの値は反復ごとに異なり、ユーザーが保存ボタンをクリックすると保存されるはずです。

       String [] sizes = {"A","B","C","D"};
        for (int i = 0; i <= sizes.length-1 ; i++){
            try {
                String x = sizes[i];
                Intent intents = new Intent();
                intents.setClass(Sizes.this, Sizes.class);

                Bundle bundles = new Bundle();
                bundles.putCharSequence("sizes", x);
                intents.putExtras(bundles);
                startActivity(intents);
                doSave();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

サイズごとに異なる値が読み込まれるため、ループ内のすべての値のレイアウトを SD カードに保存する必要があります。私のdoSave():

         public void doSave() throws IOException, InterruptedException {

    RelativeLayout imagevw =(RelativeLayout)findViewById(R.id.sizelayout);
    Bitmap b = Bitmap.createBitmap(imagevw.getWidth(), imagevw.getHeight(), Bitmap.Config.ARGB_8888);

    int weight,height;

    weight =  imagevw.getWidth();

    height =  imagevw.getHeight();

    Bitmap cs = Bitmap.createBitmap(weight, height, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(cs);

    c.drawBitmap(b,0,0,null);

    imagevw.draw(c);

    String getDirPath = Environment.getExternalStorageDirectory().getAbsolutePath(); 
    File myDirPath = new File(getDirPath +"/Size");

    if(!myDirPath.exists()){

        myDirPath.mkdir();

    }

    File file1 = new File("/sdcard/size/"+size+"saved image.png");
FileOutputStream fos = new FileOutputStream(file1);

if (fos != null) {

cs.compress(Bitmap.CompressFormat.PNG, 90, fos);

fos.close();
    }

    }

単一のレイアウトを保存すると、うまく保存されます。問題は、ループが完了したときに、保存ボタンをクリックする前に現在のレイアウトを現在の値で保存するだけであることです。つまり、現在のレイアウトのみを保存しています。値が異なるため、ループごとにレイアウトを保存するにはどうすればよいですか。その場合、「サイズ+「保存された image.png」サイズがバンドルであることに注意してください。

4

1 に答える 1