In my layout there are four sections respectively a header, an editable control, a list and a set of button. I want to keep the buttons bottom of the screen. I make too many changes in the layout to force the buttons to bottom. But nothing happened. Please provide instructions to make what i needed. I am posting the layout also
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- heading for basic settings -->
<TextView
android:id="@+id/setup_macroheading"
style="@style/txtHeading" />
<View
android:layout_width="fill_parent"
android:layout_height="20dp"/>
<!-- macro name -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:textColor="@color/white"
android:text="Macro Name"/>
<EditText
android:id="@+id/setup_macroname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:maxLength="12"
android:inputType="textCapCharacters"
android:singleLine="true"/>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="20dp"/>
<ListView
android:id="@+id/lvMacroList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<!-- Save & Cancel button -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_gravity="bottom"
android:orientation="horizontal">
<Button
android:id="@+id/setup_macroSavebtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:onClick="onSaveButtonClick"
android:text="Save"/>
<Button
android:id="@+id/setup_macroCancelbtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:onClick="onCancelButtonClick"
android:text="Cancel"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Make the Parent of the LinearLayout containing the button as relative and set the property of linear layout containing two buttons as android:layout_alignParentBottom="true". You can also set the gravity of the Linear Layout to Bottom.
Try this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- heading for basic settings -->
<TextView
android:id="@+id/setup_macroheading"
style="@style/txtHeading" />
<View
android:layout_width="fill_parent"
android:layout_height="20dp"/>
<!-- macro name -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:textColor="@color/white"
android:text="Macro Name"/>
<EditText
android:id="@+id/setup_macroname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:maxLength="12"
android:inputType="textCapCharacters"
android:singleLine="true"/>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="20dp"/>
<ListView
android:id="@+id/lvMacroList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<!-- Save & Cancel button -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<Button
android:id="@+id/setup_macroSavebtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:onClick="onSaveButtonClick"
android:text="Save"/>
<Button
android:id="@+id/setup_macroCancelbtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:onClick="onCancelButtonClick"
android:text="Cancel"/>
</LinearLayout>
</RelativeLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With