0

I would like to have a fixed footer something like this:

enter image description here

I tried to achieve this using relative layout:

   <RelativeLayout
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/_12sdp"
        android:layout_alignParentBottom="true">
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_gravity="center_horizontal"
            android:textColor="@color/material_grey_850"
            android:gravity="center_horizontal"
            android:text="Version 1.0 Demo"
            android:layout_marginTop="@dimen/_22sdp"
            android:textSize="@dimen/_15sdp"
            android:id="@+id/versionText" />
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_gravity="center_horizontal"
            android:textColor="@color/material_grey_850"
            android:gravity="center_horizontal"
            android:text="Copyright (c) 2017 Aglive Pty Ltd"
            android:layout_marginTop="@dimen/_8sdp"
            android:textSize="@dimen/_15sdp"
            android:id="@+id/copyrightText"
            android:layout_alignParentBottom="false"
            android:layout_below="@id/versionText" />
        <RelativeLayout
            android:orientation="vertical"
            android:layout_column="0"
            android:layout_row="2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_columnSpan="7"
            android:layout_marginTop="7.0dp"
            android:layout_marginBottom="7.0dp"
            android:id="@+id/relative"
            android:layout_below="@id/copyrightText">
            <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_gravity="center_horizontal"
                android:textColor="@color/material_grey_850"
                android:gravity="center_horizontal"
                android:text="Terms of Service"
                android:layout_marginTop="21.5sp"
                android:layout_alignParentBottom="true"
                android:textSize="@dimen/_15sdp"
                android:layout_marginRight="5.5sp"
                android:id="@+id/termsOfService"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="@dimen/_15sdp" />
            <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_gravity="center_horizontal"
                android:textColor="@color/material_grey_850"
                android:gravity="center_horizontal"
                android:text="Contact Us"
                android:layout_marginTop="21.5sp"
                android:layout_alignParentBottom="true"
                android:textSize="@dimen/_15sdp"
                android:layout_marginRight="@dimen/_15sdp"
                android:id="@+id/contactUs"
                android:layout_alignParentRight="true" />
        </RelativeLayout>
    </RelativeLayout>

But the problem here is that whenever the keyboard opens up the footer moves up. For which I tried to add WindowSoftInputMode = SoftInput.AdjustPan. It worked for the keyboard issue but whenever the screen rotates to landscape mode the footer overlaps the other text. Also my relative layout does not come as required. The relative layout seems to be covering other text.

Onik
  • 19,396
  • 14
  • 68
  • 91
Arti
  • 2,993
  • 11
  • 68
  • 121
  • than set orientation **`android:screenOrientation="portrait"`** to your activity – Goku Nov 18 '17 at 04:34
  • I want may app to have both screen orientation!! – Arti Nov 18 '17 at 04:35
  • than use **`Constraint layout`** – Goku Nov 18 '17 at 04:36
  • this link may help you https://stackoverflow.com/questions/2124046/how-do-i-specify-different-layouts-for-portrait-and-landscape-orientations and this https://stackoverflow.com/questions/4858026/android-alternate-layout-xml-for-landscape-mode and this https://stackoverflow.com/questions/28815769/android-studio-creating-landscape-layouts – Goku Nov 18 '17 at 04:41
  • I think that you should put your current layout into `ScrollView`. When the keyboard opens you calculate a distance from top to a view that you want to display(depends on the screen size, keyboard height, etc.). After that, you request the `ScrollView` to scroll to a position depends on the calculated distance. – John Le Nov 18 '17 at 04:45

2 Answers2

0

If you want to have both modes in the app then you have to make an xml with same name placed in folder layout-land along with the one you have made. With this you will have different layouts for both portrait and landscape and hence this will solve your problem. Hope this helps.

Sarthak Gandhi
  • 2,130
  • 1
  • 16
  • 23
  • So does that mean for each and every page where I have a footer, I will have to design it twice for two different modes? – Arti Nov 20 '17 at 05:13
  • Yes.. it is relatively easy than it looks. Once one layout is done. Rest are really easy. – Sarthak Gandhi Nov 20 '17 at 05:17
0

Adding,

android:configChanges="keyboardHidden|orientation|screenSize"

into your <activity> node in manifest.xml will do the trick.

now, you can listen configuration changes into an override method onConfigurationChanged in your activity.

@Override
public void onConfigurationChanged(Configuration newConfig) {
  super.onConfigurationChanged(newConfig);
  // Perform any action here... resetting the layout or.. values or smoething
}
Paresh P.
  • 6,677
  • 1
  • 14
  • 26
  • What should I do in this method? My footer overlaps the content in landscape mode what possibly should I do here? – Arti Nov 20 '17 at 05:11
  • Adding `android:configChanges="keyboardHidden|orientation|screenSize"` did not work? – Paresh P. Nov 20 '17 at 05:14
  • Simply adding `android:configChanges="keyboardHidden|orientation|screenSize‌​"` did not work. What should i do in onConfigurationChanged? – Arti Nov 20 '17 at 05:17
  • Application crashes if i add `setContentView(R.layout.Layout_id)` in `onConfigurationChanged` – Arti Nov 20 '17 at 05:30
  • Make sure you are writing that after `super()`. Post an error about the crash if possible! – Paresh P. Nov 20 '17 at 06:36