Android:关于解决ImageButton添加图片后运行无法显示的问题

这是我的ImageButton在xml文件中的代码

<ImageButton
    android:id="@+id/recentralization"
    android:layout_width="50dp"
    android:layout_height="0dp"
    android:layout_gravity="left|bottom"
    android:layout_marginBottom="28dp"
    android:layout_marginStart="16dp"
    android:background="@drawable/recentralize"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/linearLayout2" />

然后在布局文件中显示了

Android:关于解决ImageButton添加图片后运行无法显示的问题

但是在运行的时候 却无法显示

Android:关于解决ImageButton添加图片后运行无法显示的问题

 

好了现在重新来看下我写在xml文件中代码,仔细看会发现

android:layout_height="0dp"

这个居然是0!!!这当然显示不出来

修改以后成功显示

Android:关于解决ImageButton添加图片后运行无法显示的问题所以说! 一定要仔细写代码!