【发布时间】:2015-09-16 10:24:09
【问题描述】:
我正在尝试为调用活动中单选按钮上的不同选项更改 ImageView 的背景图像。调用活动将捆绑中的参数传递给渲染活动,并且我正在正确接收参数(在单选按钮上做出选择后,我将 Curve1 和 Curve2 作为渲染活动中的参数)。但我无法通过 setImageResource() 或 setBackgroundResource() 更改图像背景。 这是 sn-p 这样做的:
渲染活动
private void validateImage()
{ wave = (ImageView) findViewById(R.id.image_wave);
switch (extras.getString("Curve"))
{
case "Curve1":
wave.setB (R.drawable.sinewave1);
break;
case "Curve2":
wave.setImageResource(R.drawable.sinewave2);
break;
}
}
activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="shantanu.concussion.usu.concussiontest.TestActivity">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/image_wave"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
谁能建议我错过了什么? 谢谢:-)
【问题讨论】:
-
参考stackoverflow.com/questions/11893826/… 对您的问题很有用
-
我尝试在更改图像背景后使用 invalidate(),但没有帮助,我在 UI 线程上执行此操作,因此,invalidate 应该是重绘请求的选择。