Reputation: 13
Picture 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
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
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
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
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