-2

imageViewで使用されるR.javaから画像のIDにアクセスしたいアプリケーションに取り組んでいます。例えば

imageView i;
i=(ImageView)findViewbyid(imageview1);
i.setImageResource(R.drawble.human); 
.....

今、私は実行中のアプリケーションでどのIDが使用されているか知りたいです。

4

3 に答える 3

0

ImageView の画像の背景を取得する方法を探している場合は、これが役に立ちます。

   ImageView imageView=(ImageView)findViewById(R.id.image);
       imageView.setBackgroundResource(R.drawable.ic_launcher);
      imageView.setDrawingCacheEnabled(true);
      Drawable d=imageView.getBackground();
于 2012-05-16T09:43:23.297 に答える
0

//ドローアブルに画像を配置すると、R.java ファイルに ID が生成されます

その特定の画像を ImageView に表示する場合

このように宣言する必要があります

public static Integer[] images = new Integer[]{R.drawable.my_love,R.drawable.first,R.drawable.second,R.drawable.third};

次に、画像リソースを次のように設定します。

ImageView i = new ImageView(this.context);
i.setImageResource(this.images[1]);

//あなたは次のように宣言しました

imageView i=(ImageView)findViewbyid(imageview1);

//この imageview1 は何ですか?

代わりに、xml 宣言の ImageView id を次のように指定する必要があります。

 imageView i=(ImageView)findViewbyid(R.id.imageview);
于 2012-05-16T08:26:05.110 に答える
0

これにより、ドローアブル内の画像のIDが得られます

String mDrawableName =Integer.toString( R.drawable.human);              
int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());
于 2012-05-19T13:02:56.363 に答える