0

をしようとしsetBackgroundResourceImageViewいますが、うまくいきません。

XML:

<ImageView
    android:id="@+id/img_index"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_marginBottom="4dp"
    android:background="@drawable/homegray"
    android:gravity="center_horizontal|center_horizontal"
    android:paddingBottom="4dp"
/>

活動コード:

imgIndex = (ImageView) this.findViewById(R.id.img_index);
imgIndex.setBackgroundResource(R.drawable.homewhite);

を制御するにはどうすればよいImageViewですか?

4

1 に答える 1

4

これを試して。

imgIndex = (ImageView) findViewById(R.id.img_index);
imgIndex.setImageResource(R.drawable.homewhite);

また

imgIndex = (ImageView) findViewById(R.id.img_index);
imgIndex.setImageDrawable(getResources().getDrawable(R.drawable.homewhite));
于 2013-05-31T03:46:30.620 に答える