Search code examples
androidtextviewfooterandroid-bottomnav

How to fix footer alignParentBottom="true" in scrollview layout


The problem I experienced when (Linearlayout) was set to alignParentBottom which contained it (TextView) and then pack RelativeLayout with scrollview (so that when the Keyboard appears all the views can be seen) - However, when the Keyboard appears and the ScrollView TextView mode becomes irregular with others textview (such as Pictures).

how to fix my problem below, I want alignParentbottom to have space when the scrollview and keyboard appear.

Image https://2.bp.blogspot.com/-7oX2mpmzFas/XLxdIH6x1OI/AAAAAAAAA-g/MNL4mIr_Pr85isMBc05LNTvTyQAwimmLgCLcBGAs/s1600/Graphic1.jpg

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">

<RelativeLayout
android:id="@+id/badan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:gravity="center_vertical"
android:padding="20dp">

<!--  Header Starts-->

<LinearLayout android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:layout_marginTop="50dp"
android:layout_marginBottom="15dp"
android:gravity="center"
android:paddingBottom="5dip">

<!-- Logo Start-->

<ImageView android:src="@drawable/logo"
android:layout_width="100dp"
android:layout_height="100dp"/>

<!-- Logo Ends -->

</LinearLayout>

<!--  Header Ends -->

<!-- Login Form -->

<LinearLayout
android:id="@+id/loginform"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_below="@id/header">

<!--  Email Label -->

<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:padding="10dp"
android:background="@drawable/forminput"
android:inputType="textEmailAddress"
android:singleLine="true"
android:hint="Email" />

<!--  Password Label -->

<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="10dp"
android:background="@drawable/forminput"
android:singleLine="true"
android:inputType="textPassword"
android:hint="Kata Sandi"/>

<!-- Login button -->
<Button android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="@drawable/button"
android:text="Login"
android:textColor="@color/white"
android:textSize="17dp"/>

<!-- Link to Registration Screen -->

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Lupa detail informasi masuk Anda? Dapatkan bantuan untuk masuk."
android:textSize="14sp"
android:gravity="center"/>
</LinearLayout>

</LinearLayout>

<!-- Login Form Ends -->

<!-- Footer Start-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:gravity="center"
android:layout_height="wrap_content"
android:padding="15dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tidak punya akun?"
android:textSize="14sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Buat akun."
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<!-- Footer Ends -->    

</RelativeLayout>

</ScrollView>

Solution

  • You could add android:windowSoftInputMode="adjustPan" in your AndroidManifest.xml file

    Give id to your footer.(android:id="@+id/footer").And add this in you activity

    LinearLayout footer = (EditText) findViewById(R.id.footer);
    
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(editTextSearch.getWindowToken(), 0);
    

    If it doesn't work, you should wrap your ScrollView with RelativeLayout

    <RelativeLayout>
       <ScrollView>
           ......
       </ScrollView>
    </RelativeLayout>