1

I have a Imagebutton with a icon of a barcode as the background. I am trying to put a paddingtop on the item so its not touching the top of the screen.

The paddingtop works for the textview but not the imagebutton?

Any tricks I can try to move it 5dp down?

<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>

enter image description here

Greg
  • 1,715
  • 5
  • 27
  • 36

1 Answers1

1

Use layout margin to move the image button down.

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

See this answer for more on margin versus padding.

Community
  • 1
  • 1
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • Thanks a lot. I've been struggling with this for ages! :) Works perfectly and great link. – Greg Feb 28 '15 at 09:26