这是我的布局文件的片段:
<linearLayout androID:layout_wIDth="match_parent" androID:layout_height="39dp" androID:gravity="center_vertical" > <ImageVIEw androID:ID="@+ID/qStatusImage" androID:layout_wIDth="16dp" androID:layout_height="16dp" androID:layout_margin="5dp" androID:background="@drawable/thumbs_down" /> <TextVIEw androID:ID="@+ID/grp_child" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:textcolor="@color/radio_colors" androID:textStyle="normal" androID:background="@color/grey" /> </linearLayout>
以及设置imageVIEw的代码:
@OverrIDepublic VIEw getChildVIEw(final int groupposition,final int childposition,boolean isLastChild,VIEw convertVIEw,VIEwGroup parent) {//Answers if(answersGroup != null) answersGroup.setonCheckedchangelistener(new OnCheckedchangelistener() { @OverrIDe public voID onCheckedChanged(RadioGroup group,int checkedID) { // int index = answersGroup.indexOfChild(findVIEwByID(answersGroup.getCheckedRadiobuttonID())); qImageVIEw = (ImageVIEw) V.findVIEwByID(R.ID.qStatusImage); if(ans ==0 || ans == 5){ // qSV.setimageResource(0); qImageVIEw.setimageResource(R.drawable.thumbs_up); } else qImageVIEw.setimageResource(R.drawable.thumbs_down); } });
我错过了什么?
解决方法 之所以发生这种情况,是因为您要设置ImageVIEw的src而不是背景.请改用:
qImageVIEw.setBackgroundResource(R.drawable.thumbs_down);
Here是一个讨论两种方法之间差异的线索.
总结以上是内存溢出为你收集整理的在Android中以编程方式更改ImageView的图像全部内容,希望文章能够帮你解决在Android中以编程方式更改ImageView的图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)