I have the following code for my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_color"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:text=""
android:textColor="@color/text_color"
android:textSize="@dimen/nav_text_size" >
</TextView>
<Button
android:id="@+id/ProceedToScreen31"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_action_name"
android:gravity="left|center_vertical"
android:text="@string/TA1"
android:textColor="@color/btn_text_color"
android:textSize="@dimen/button_text_size" >
</Button>
<Button
android:id="@+id/ProceedToScreen32"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_action_name"
android:gravity="left|center_vertical"
android:text="@string/TA2"
android:textColor="@color/btn_text_color"
android:textSize="@dimen/button_text_size" >
</Button>
<Button
android:id="@+id/ProceedToScreen33"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_action_name"
android:gravity="left|center_vertical"
android:text="@string/TA3"
android:textColor="@color/btn_text_color"
android:textSize="@dimen/button_text_size" >
</Button>
<Button
android:id="@+id/ProceedToScreen34"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_action_name"
android:gravity="left|center_vertical"
android:text="@string/TA4"
android:textColor="@color/btn_text_color"
android:textSize="@dimen/button_text_size" >
</Button>
<View
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="@color/line_color" >
</View>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/copyright"
android:textColor="@color/text_color"
android:textSize="@dimen/small_text_size" >
</TextView>
</LinearLayout>
</ScrollView>
</LinearLayout>
The problem with this is that when I turn my phone to landscape, the buttons don't expand and fill only half of the screen.
How can I get my buttons to expand to fill the rest of the screen?
Your buttons are ok, but their parent(Linear Layout) isn't as big as the screen because its width is set to wrap_content. Just change to match_parent and you will be ok.
match_parent = Sets the dimension to match that of the parent element. Added in API Level 8 to deprecate fill_parent.
Hope this helps