I have a header that I am working on and I got the buttons to render in a single row, but one button does not fit on the screen and there is a space between the buttons.
Here is my layout for the header so far:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/home"
android:layout_width="0dp"
android:orientation="horizontal"
android:layout_height="10dp"
android:layout_weight="1"
android:text="Home"
/>
<Button android:id="@+id/questions"
android:layout_width="0dp"
android:layout_height="10dp"
android:orientation="horizontal"
android:layout_weight="1"
android:text="Questions"
android:layout_toRightOf="@+id/home" />
<Button android:id="@+id/businesses"
android:layout_width="0dp"
android:layout_height="10dp"
android:orientation="horizontal"
android:layout_weight="1"
android:text="Businesses"
android:layout_toRightOf="@+id/questions"
/>
<Button android:id="@+id/learn"
android:layout_width="0dp"
android:layout_height="10dp"
android:layout_weight="1"
android:orientation="horizontal"
android:text="Learn"
android:layout_toRightOf="@+id/businesses"
/>
<Button android:id="@+id/extra_help"
android:layout_width="0dp"
android:layout_height="10dp"
android:orientation="horizontal"
android:layout_weight="1"
android:text="Help"
android:layout_toRightOf="@+id/learn"
/>
</LinearLayout>
How can I make each button smaller, and make it so there is no space between them? Also, what is some devices have narrower screens? How do I make sure the header fits into all the screens?
Thanks!
You could use a
LinearLayoutand set each of theButton‘slayout_widthto0dpandlayout_weightto1. That way, the entire space of theLinearLayoutwould be equally distributed among yourButtons.