在Android中以编程方式更改ImageView的图像

在Android中以编程方式更改ImageView的图像,第1张

概述当我以编程方式更改图像时,它会在最初在布局文件中设置的旧图像上显示新图像? 这是我的布局文件的片段: <LinearLayout android:layout_width="match_parent" android:layout_height="39dp" android:gravity="center_vertical" > <ImageView 当我以编程方式更改图像时,它会在最初在布局文件中设置的旧图像上显示新图像?

这是我的布局文件的片段:

<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的图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1121536.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存