user1816999
user1816999

Reputation: 13

evenly distributing icons in relative layout

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.sstatic.net/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.

Upvotes: 0

Views: 2901

Answers (4)

jcw
jcw

Reputation: 5162

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 -

Upvotes: 0

user1455310
user1455310

Reputation:

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/

Upvotes: 0

Binoy Babu
Binoy Babu

Reputation: 17119

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.

Upvotes: 2

Gabe Sechan
Gabe Sechan

Reputation: 93559

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.

Upvotes: 1

Related Questions