imageView中的图像背景不使用setImageResource()进行更改

时间:2015-09-16 01:48:27

标签: android android-imageview

我正在尝试在调用活动中的单选按钮上为不同选项更改ImageView的背景图像。调用活动将包中的参数传递给渲染活动,并且我正在接收参数(在单选按钮上选择后,我将Curve1和Curve2作为渲染活动中的参数)。但我无法通过setImageResource()或setBackgroundResource()更改图像背景。 这是代码片段:

渲染活动

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" />

有人能说出我错过了什么吗? 谢谢: - )

2 个答案:

答案 0 :(得分:0)

尝试手动调用invalidate。暴力改变最少的东西。您需要了解问题所在(错误选择View,View不会更改)尝试更改另一个属性,例如。

可能导致资源。 (例如,它是透明的)

检查分支开关的入口。 (也许是错误的比较)

通过编辑器更改属性。也许某些东西会阻止显示背景。

这只是一个愚蠢的错误。

答案 1 :(得分:0)

wave.setImageDrawable(getResources().getDrawable(R.drawable.sinewave2));
相关问题