简体   繁体   English

修复了Android中横向和纵向模式下的页脚

[英]Fixed footer in landscape and portrait mode in Android

I would like to have a fixed footer something like this: 我想要一个固定的页脚,如下所示:

在此处输入图片说明

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 . 为此,我尝试添加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. 相对布局似乎覆盖了其他文本。

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. 如果要在应用程序中同时使用这两种模式,则必须将具有相同名称的xml与已创建的xml一起放置在文件夹layout-land中。 With this you will have different layouts for both portrait and landscape and hence this will solve your problem. 这样,您将在纵向和横向上具有不同的布局,因此可以解决您的问题。 Hope this helps. 希望这可以帮助。

Adding, 添加,

android:configChanges="keyboardHidden|orientation|screenSize"

into your <activity> node in manifest.xml will do the trick. 进入manifest.xml <activity>节点即可解决问题。

now, you can listen configuration changes into an override method onConfigurationChanged in your activity. 现在,您可以在活动onConfigurationChanged配置更改侦听为onConfigurationChangedoverride方法。

@Override
public void onConfigurationChanged(Configuration newConfig) {
  super.onConfigurationChanged(newConfig);
  // Perform any action here... resetting the layout or.. values or smoething
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM