将图像设置为在布局中包含图像视图

Set Image to included imageview in a layout

我尽量说得通俗点。

我要参加活动:

in activity B 我正在尝试通过代码在活动 A 中为图像视图设置图像。但我得到了力量关闭!

ImageView iv =(Imageview) findviewbyid(R.id.activityAimageview);
iv.setBackgroundResource(R.drawable.pic);

我希望是否有办法在 activity A 中为该图像视图设置图像。

这里有一个糟糕的设计问题。

一个activity在另一个activity没有意义。每个 activity 都必须是唯一的,并留出用于特定任务。

你想做的,可以用:片段来完成。

  1. 别碰Activity B.
  2. 将 Activity A 更改为片段。
  3. 在 Activity B 中的 ImageView 旁边添加 Fragment A。

然后在 activity B 中你总是可以使用 findviewbyid() 函数(在 setContentView() 之后),而在 Fragment A 中你总是可以使用 [= 访问 Activity B 12=]函数。

要了解 Fragment,请从以下位置开始阅读:
https://developer.android.com/guide/components/fragments.html