0

Picture here:

enter image description here

How to evenly distribute these three icons (with 1dp gap in between and another 1dp margin on both edges) regardless of the screen size ?

I am using relative layout.

Thanks !

EDIT Progress: https://i.stack.imgur.com/RcBre.jpg

<ImageButton
                android:id="@+id/imageButton6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/text" 
                android:background="@null"
                android:paddingLeft="2dp"/>

still not getting any padding between the icons.

user1816999
  • 13
  • 1
  • 4

4 Answers4

2

To acheive the effect use (be sure to use Linear_Layout)

android:layout_width="match_parent"
android:layout_height="wrap_content"
andorid:padding="0.5dp"
android:layout_weight="1"

in each widgets. layout_weight is used specify size ratio between sister widgets.

Binoy Babu
  • 16,699
  • 17
  • 91
  • 134
1

I wouldn't use a relative layout for that, use a linear layout. Set all 3 to fill_parent and a layout weight of 1. That should work.

If you do need a relative layout for other reasons, put a linear layout inside of the relative layout and put the icons inside the linear layout.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

To each of your icons add the following attribute -

android:paddingLeft="1dp" - on the left

To only the last icon add

android:paddingRight ="1dp" - on the right

This will give each of you icons a black area around it. You may have to look into scaling that last image on the right, because even with the padding it may not fit.

Also, if you want to scroll through those images, then you should use a HorizontalScrollView -

Community
  • 1
  • 1
jcw
  • 5,132
  • 7
  • 45
  • 54
0

If you need to display images in a uniform manner, you can use GridView in your layout and pass the images using an Adapter class.

For more info, you can refer developer site: http://developer.android.com/guide/topics/ui/layout/gridview.html

For a simple example code, you can refer this link: http://www.mkyong.com/android/android-gridview-example/