~随心~ 2022-03-16 14:35 采纳率: 81.8%
浏览 194
已结题

Android Studio开发,ImageView使用setBackgroundResource()更换背景之后,是图片叠在原来图片下面,怎么替换呢?


                <com.example.platform.ProgressImageView
                    android:id="@+id/k1"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:layout_marginLeft="100dp"
                    android:background="@mipmap/xu1" /

这是定义的ImageView,在MainActivity中使用


image.setBackgroundResource(R.minmap.background);

但是效果是下面这样,是叠在一起的,不是替换,

img


请问有什么方法能把原来的图片去掉,替换成新图片呢?

  • 写回答

2条回答 默认 最新

  • 光临天下 2022-03-16 15:42
    关注

    image.setBackgroundResource(null);
    image.setBackgroundResource(R.minmap.background);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
    1人已打赏
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月24日
  • 已采纳回答 3月16日
  • 创建了问题 3月16日