Reputation: 6128
i am trying to make a Linear Layout with 5 buttons horizontally placed with equal spacing, but all the buttons size (width) should be 40dp only.
i tried this :
<LinearLayout android:id="@+id/button_layout"
android:background="#DCE1DC"
android:orientation="horizontal"
android:weightSum="5"
android:layout_width="fill_parent"
android:layout_height="70dip">
<Button android:id="@+id/button_A"
android:layout_weight="1"
android:layout_height="60dp"
android:layout_width="0dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="30dp"/>
<Button android:id="@+id/button_B"
android:layout_weight="1"
android:layout_height="60dp"
android:layout_width="0dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="30dp"/>
<Button android:id="@+id/button_C"
android:layout_weight="1"
android:layout_height="60dp"
android:layout_width="0dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="30dp"/>
<Button android:id="@+id/button_D"
android:layout_weight="1"
android:layout_height="60dp"
android:layout_width="0dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="30dp"/>
<Button android:id="@+id/button_E"
android:layout_weight="1"
android:layout_height="60dp"
android:layout_width="0dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="30dp"
android:layout_marginLeft="30dp"/>
</LinearLayout>
its working but i need the buttons width to be smaller , how to acheive this?
Upvotes: 5
Views: 9046
Reputation: 8843
i guess this will resolve your query...
as you say you are using Linearlayout then you can do something like...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="yourheight"
android:orientation="horizontal">
<Button
android:id="@+id/button_name"
android:weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<Button
android:id="@+id/button_name"
android:weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
//add as many buttons as you want
<Button
android:id="@+id/button_name"
android:weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</LinearLayout>
Upvotes: 3
Reputation: 12656
For each button, change this:
android:layout_width="0dp"
To this:
android:layout_width="40dp"
Upvotes: 1