【问题标题】:Fixed footer in landscape and portrait mode in Android修复了 Android 中横向和纵向模式下的页脚
【发布时间】:2018-05-01 22:20:04
【问题描述】:

我想要一个像这样的固定页脚:

我尝试使用相对布局来实现这一点:

   <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>

但这里的问题是,每当键盘打开时,页脚就会向上移动。为此我尝试添加WindowSoftInputMode = SoftInput.AdjustPan。它适用于键盘问题,但只要屏幕旋转到横向模式,页脚就会与其他文本重叠。我的相对布局也不是按要求来的。相对布局似乎覆盖了其他文本。

【问题讨论】:

标签: android footer android-relativelayout


【解决方案1】:

如果您想在应用程序中同时使用这两种模式,那么您必须创建一个同名的 xml,并将其与您创建的那个一起放置在文件夹 layout-land 中。有了这个,您将有不同的纵向和横向布局,因此这将解决您的问题。希望这会有所帮助。

【讨论】:

  • 那么这是否意味着对于我有页脚的每个页面,我都必须为两种不同的模式设计两次?
  • 是的.. 它比看起来相对容易。一旦一个布局完成。休息真的很容易。
【解决方案2】:

添加,

android:configChanges="keyboardHidden|orientation|screenSize"

进入manifest.xml 中的&lt;activity&gt; 节点就可以了。

现在,您可以在 Activity 中将配置更改监听到 override 方法 onConfigurationChanged

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

【讨论】:

  • 这种方法应该怎么做?我的页脚与横向模式下的内容重叠,我应该在这里做什么?
  • 添加 android:configChanges="keyboardHidden|orientation|screenSize" 无效?
  • 简单地添加android:configChanges="keyboardHidden|orientation|screenSize‌​" 不起作用。我应该在 onConfigurationChanged 中做什么?
  • 如果我在onConfigurationChanged 中添加setContentView(R.layout.Layout_id),应用程序会崩溃
  • 确保你在super()之后写了那个。如果可能,请发布有关崩溃的错误!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-24
  • 1970-01-01
  • 1970-01-01
  • 2015-09-09
相关资源
最近更新 更多