Android 在button 上添加imageview不显示

首先.xml 界面布局如下

<Button
    android:id="@+id/shopDepositBtn"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_marginTop="12dp"
    android:layout_marginStart="0dp"
    android:layout_marginEnd="0dp"
    android:text="@string/shopsetting_shopdeposit"
    android:paddingStart="15dp"
    android:textSize="16sp"
    android:gravity="center_vertical"
    android:background="@color/white"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/shopAuthenticationBtn"/>
  <ImageView
    android:id="@+id/shopDepositImageV"
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:layout_marginTop="15dp"
    android:layout_marginBottom="15dp"
    android:layout_marginEnd="15dp"
    app:layout_constraintBottom_toBottomOf="@+id/shopDepositBtn"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="@+id/shopDepositBtn"
    android:src="@drawable/arrow"
    tools:ignore="ContentDescription"/>

其中布局效果图:

模拟器/真机运行效果图:

分析:通过调整图片大小猜测:是因为图片被遮盖,所以显示不出来。

而被遮盖的原因是因为:

默认button 下会有阴影效果,不仅抬升了button 的位置,而且把Button的优先级提高了(原来button 和imageview 同等级,imageView后添加,理论上可以覆盖在Button上,但是有阴影效果的button 优先级是提高了,所以会覆盖在imageview上方)

解决方法:

在Button里面添加属性:

android:stateListAnimator="@null"

效果如下:

 

  

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

app开发工程师V帅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值