Reputation: 6451
I use this code to draw the following line
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_weight=".25"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<Button
android:id="@+id/Chemo"
android:layout_width="match_parent"
android:layout_weight="0.33"
android:layout_height="wrap_content"
android:text="Chemo"
android:background="@drawable/firstbuttoncolorstyle"
android:textColor="@drawable/firstbuttontextstyle"
android:layout_gravity="center"
android:textSize="22dp"
/>
<Button
android:id="@+id/inpatient"
android:layout_width="match_parent"
android:layout_weight="0.33"
android:layout_height="wrap_content"
android:text="inpatient"
android:background="@drawable/firstbuttoncolorstyle"
android:textColor="@drawable/firstbuttontextstyle"
android:layout_gravity="center"
android:textSize="22dp"
/>
<Button
android:id="@+id/Mgmt"
android:layout_width="match_parent"
android:layout_weight="0.33"
android:layout_height="wrap_content"
android:text="Mgmt"
android:background="@drawable/firstbuttoncolorstyle"
android:textColor="@drawable/firstbuttontextstyle"
android:layout_gravity="center"
android:textSize="22dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/PFinder"
android:layout_width="match_parent"
android:layout_weight="0.23"
android:layout_height="wrap_content"
android:text="Patient"
android:background="@drawable/secondbuttoncolorstyle"
android:textColor="@drawable/secondbuttontextstyle"
android:layout_gravity="center"
android:textSize="22dp"
/>
<Button
android:id="@+id/Afinder"
android:layout_width="match_parent"
android:layout_weight="0.23"
android:layout_height="wrap_content"
android:text="Appointement"
android:background="@drawable/secondbuttoncolorstyle"
android:textColor="@drawable/secondbuttontextstyle"
android:layout_gravity="center"
android:textSize="22dp"
/>
<Button
android:id="@+id/Calender"
android:layout_width="match_parent"
android:layout_weight="0.23"
android:layout_height="wrap_content"
android:text="Calender"
android:background="@drawable/secondbuttoncolorstyle"
android:textColor="@drawable/secondbuttontextstyle"
android:layout_gravity="center"
android:textSize="22dp"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/Profile"
android:layout_width="match_parent"
android:layout_weight="0.33"
android:layout_height="wrap_content"
android:text="Profile"
android:background="@drawable/thirdbuttoncolorstyle"
android:textColor="@drawable/secondbuttontextstyle"
android:layout_gravity="center"
android:textSize="22dp"
/>
<Button
android:id="@+id/Clear"
android:layout_width="match_parent"
android:layout_weight="0.33"
android:layout_height="wrap_content"
android:text="Clear"
android:background="@drawable/thirdbuttoncolorstyle"
android:textColor="@drawable/secondbuttontextstyle"
android:layout_gravity="center"
android:textSize="22dp"
/>
<Button
android:id="@+id/Logout"
android:layout_width="match_parent"
android:layout_weight="0.33"
android:layout_height="wrap_content"
android:text="Logout"
android:background="@drawable/thirdbuttoncolorstyle"
android:textColor="@drawable/secondbuttontextstyle"
android:layout_gravity="center"
android:textSize="22dp"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_weight="0.25"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageButton
android:id="@+id/maillme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/mail"
android:layout_gravity="center"
/>
<ImageButton
android:id="@+id/callme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/call"
android:layout_gravity="center"
/>
</LinearLayout>
</LinearLayout>
but the following is the output
how to set space between the buttons and make for example the calender word in one line
Best regards
Upvotes: 0
Views: 10751
Reputation: 747
First of all, you should use Styles to reduce the length of code by reusing attributes like: gravity, layout_height, textColor, ...
As for the line breaks in some buttons. If you only deal with tablets you could use layout_width="wrap_content"
to avoid the line breaks and have equal height for each button.
To have a little space between each button use the already mentioned layout_marginLeft
Upvotes: 0
Reputation: 8604
Set android:layout_marginLeft = "5dp"
on every button after first Button
, I think you can use android:singleLine = "true"
to keep text in one line.
Also set the height to all buttons eual and use android:layout_height = "wrap_content"
on your main layout.
Upvotes: 0
Reputation: 5996
By looking at your example, you should reduce the textSize to 20... So calendar
& impatient
will fit in appropriately.
just a tip : use sp
for textsize and dp
for height and width of controls.
For margin you have : android:layout_marginRight
and android:layout_marginLeft
Hope it helps !
Upvotes: 2
Reputation: 33495
for spacing you can use android:layout_marginRight
, android:layout_marginLeft
etc. properties and you should define android:layout_width="WRAP_CONTENT"
to prevent behaviour like your calendar button nad next buttons have got.
Upvotes: 1