Positioning Imagebutton in XML

Asked

Viewed 122 times

0

I have an imagebutton in a relative layout. When I put the command:

"android:layout_marginLeft="

It does the intended (move away from the left edge in x measure), but when I put:

"android:layout_marginRight=" nothing happens.

Would anyone like to explain why? or what command should I use so that the spacing is from the "beginning of the screen" on the right?

  • I couldn’t figure out why it’s not working because I don’t have access to the full component code, so it’s hard to say anything. :/

1 answer

1

This is the configuration necessary for your ImageButton align according to the start and end of the screen. Check that there is no alignment with the Parent, which in this case is the RelativeLayout.

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

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="78dp"
        android:layout_height="78dp"
        android:layout_marginLeft="10dp"
        //::layout_marginStart="10dp"
        android:layout_marginRight="10dp
        //::layout_marginEnd="10dp"
        android:src="@drawable/image_button" />

</RelativeLayout>
  • The attributes marginStart and marginEnd sane optional.
  • So I have to put the two commands necessarily? my innocence put only one of the two thinking that the other would be put automatically?

  • Not necessarily. Innocence nothing, bullshit, boy. You’re wrong with the attribute margin. Normal this.

  • If you want to apply the positioning only to the left and right, use the marginLeft and Marginright. If you want to put in both, without having to put the two attributes, use this: margin="10dp"

  • But by using the margin you are adding attributes to all positions, which are they: top bottom right left

Browser other questions tagged

You are not signed in. Login or sign up in order to post.