PaddingTop 不适用于 ImageButton

PaddingTop not working on ImageButton

我有一个带有条形码图标作为背景的图像按钮。我试图在项目上放置一个 paddingtop,这样它就不会接触到屏幕的顶部。

paddingtop 适用于 textview 但不适用于 imagebutton?

我可以尝试将其向下移动 5dp 的任何技巧吗?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent">


    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="100">

    <TableRow
        android:weightSum="100">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="clip_vertical"
        android:paddingLeft="5dp"
        android:paddingTop="10dp"
        android:layout_weight="50"
        android:text="Barcode"/>


    <ImageButton
        android:id="@+id/btnScan"
        android:paddingTop="5dp"
        android:layout_width="50dp"
        android:layout_height="25dp"
        android:background="@drawable/barcode"/>

    </TableRow>
    </TableLayout>



</RelativeLayout>

使用布局边距将图像按钮向下移动。

<ImageButton
    android:id="@+id/btnScan"
    android:layout_marginTop="5dp"
    android:layout_width="50dp"
    android:layout_height="25dp"
    android:background="@drawable/barcode"/>

有关边距与填充的更多信息,请参阅 this answer