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 回答