-6

私はあなたの親切な助けがどうしても必要です.

5(4+1) のアクティビティがあります。4つのアクティビティのいずれかで画像をクリックすると、最後の1つのアクティビティに表示したいのですが、それもフルスクリーンで...

つまり、ランダムに表示される 4 つのアクティビティがあり、いずれかのアクティビティで Image ビューをクリックすると、選択したイメージを最終アクティビティにフルスクリーンで表示したい

コードを送信するのを手伝ってください... (そして、私の計画は、アクティビティの前にそれぞれ選択されたすべての画像を表示するために 1 つのアクティビティのみを使用することであり、2 ~ 3 秒後に消えます。)

私はANDROIDプロジェクトに取り組み始めたばかりなので、どんな種類の助けも大歓迎です.ありがとう.

よし、ここだ。

MAinActivity.java

           public void onClick(View v) {

    // TODO Auto-generated method stub

    switch (v.getId()) {

    case R.id.imageView1:
    Intent i = new Intent(MainActivity.this, ImageView.class);
    i.putExtra("key1", R.drawable.ic_launcher);
    startActivity(i);

    break;

    case R.id.imageView2:
    Intent i1 = new Intent(MainActivity.this, ImageView.class);
    i1.putExtra("key1", R.drawable.ic_launcher);
    startActivity(i1);

    break;

ImageView.java:

            super.onCreate(b);      
    iv = new android.widget.ImageView(this);        
    Uri savedInstanceState = getIntent().getParcelableExtra("key1");        
    iv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));     
    iv.setImageURI(savedInstanceState);

わかりました、私は本当に 1 つの MainActivity から ImageView アクティビティにイメージを転送するためにここで立ち往生しています。

私の無実を指摘してください。

私の Main.xml ファイルには、関連する ImageView タグがあります。

4

1 に答える 1

0

3 秒後に呼び出される 1 つのメソッドを宣言できる 1 つのアクティビティを作成finish();し、それを書き込むことができます。このアクティビティでは、フルスクリーンで表示する画像名を渡すことができます。intent.putExtra

コードが必要な場合はお知らせください

ここにコードがあります

  • *アクティビティ A* でファイルを保存します (内部ストレージ)
String fileName = "SomeName.png";
try {
    FileOutputStream fileOutStream = openFileOutput(fileName, MODE_PRIVATE);
    fileOutStream.write(b);  //b is byte array 
                             //(used if you have your picture downloaded
                             // from the *Web* or got it from the *devices camera*)
                             //otherwise this technique is useless
    fileOutStream.close();
} catch (IOException ioe) {
    ioe.printStackTrace();
}
  • 場所を文字列としてアクティビティ B に渡す
Intent intent = new Intent(this, ActivityB.class);
intent.putExtra("picname", fileName);
  • *アクティビティ B* で、ファイルを取得します
Bundle extras = getIntent().getExtras();
String fileName = extras.getString("picname");
  • 画像から *drawable* を作成する
File filePath = getFileStreamPath(fileName);
Drawable d = Drawable.createFromPath(filePath.toString());
  • ImageView リソースに適用する
someImageView.setBackgroundDrawable(d);

名前で描画可能なフォルダーリソースにアクセスするには、このメソッドを使用できます

private void showImage() {
    String uri = "drawable/icon";

    // int imageResource = R.drawable.icon;
    int imageResource = getResources().getIdentifier(uri, null, getPackageName());

    ImageView imageView = (ImageView) findViewById(R.id.myImageView);
    Drawable image = getResources().getDrawable(imageResource);
    imageView.setImageDrawable(image);
}
于 2013-02-25T10:36:09.767 に答える