make same space between button in linearlayout
You can use layout_weight. But like you said Buttons will be stretched
, so instead of using weight on Buttons, use on spaces(Views).
<Button
android:id="@+id/btnFacebook"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/btn_facebook" />
<View
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1" />
<Button
android:id="@+id/btnYoutube"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/btn_youtube" />
<View
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1" />
<Button
android:id="@+id/btnTwitter"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/btn_twitter" />
<View
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1" />
<Button
android:id="@+id/btnPintrest"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/btn_pintrest" />
</LinearLayout>
To make your intent clearer in your XML use a <Space>
instead of a <View>
as follows:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/Blue"
android:orientation="horizontal" >
<Space
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" >
</Space>
<Button
android:id="@+id/btnFacebook"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/btn_facebook" />
<Space
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" >
</Space>
...and repeat with the rest of your buttons...
</LinearLayout>
give layout_weight
to every Button
1, it will divide all space