In my main activity there is a RelativeLayout that has 2 childs:

在我的主要活动中有一个有两个孩子的RelativeLayout:

  • An ImageView which serves as the background
  • 用作背景的ImageView
  • A LinearLayout that has 2 fragment containers
  • 具有2个片段容器的LinearLayout

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="bottom"
    tools:context="${packageName}.${activityClass}">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:baselineAlignBottom="false"
        android:scaleType="fitStart"
        android:src="@drawable/bg_image" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingTop="?android:attr/actionBarSize"
        android:layout_alignParentBottom="true">

        <LinearLayout
            android:id="@+id/ContainerA"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="vertical" />

        <LinearLayout
            android:id="@+id/ContainerB"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/background_gray"
            android:orientation="vertical" />

    </LinearLayout>
</RelativeLayout>

Container A simply shows a fragment that doesn't change.
However, Container B holds a fragment that does change depending on user clicks.

容器A只显示一个不会改变的片段。但是,容器B保存的片段会根据用户点击进行更改。

Container B changes in 2 ways:

容器B以两种方式改变:

  • It can expand (from a height of about 70% to full height).
  • 它可以扩展(从大约70%的高度到全高)。
  • It changes fragments.
  • 它改变了碎片。

One of the fragments Container B can hold is a form, which contains EditTexts and other views.

容器B可以容纳的一个片段是一个表单,其中包含EditTexts和其他视图。

My problem is that I can't get the activity to resize when the keyboard is open.
I set adjustResize in the manifest file and my theme is not a fullscreen theme (it is apparently a cause for this problem). I also tried to edit the views, add ScrollViews but absolutely nothing worked.

我的问题是,当键盘打开时,我无法调整活动的大小。我在清单文件中设置了adjustResize,我的主题不是全屏主题(显然这是导致此问题的原因)。我也尝试编辑视图,添加ScrollViews但绝对没有用。

The theme I'm using for this activity is the light theme with the dark actionbar from the AppCompat library. I only edited the theme to allow an overlay actionbar. This is not the problem as I've already tried removing those edits to no avail.

我正在使用的主题是使用AppCompat库中的暗动作条的轻主题。我只编辑了主题以允许叠加操作栏。这不是问题,因为我已经尝试删除这些编辑无济于事。

Here's a link to the form layout

这是表单布局的链接

TL;DR adjustResize / adjustPan do not work for me. Searched, tried various solutions, nothing worked. My question is; what is the cause for this in my case?

TL; DR adjustResize / adjustPan对我不起作用。搜索,尝试了各种解决方案,没有任何效果。我的问题是;在我的情况下,这是什么原因?

Update: AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>

    <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="19" />

    <application ... android:theme="@style/AppTheme">
        <activity android:name=".SplashScreenActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity"
            android:configChanges="keyboardHidden|screenSize" android:label="@string/app_name"
            android:screenOrientation="portrait" android:theme="@style/OverlayActionBarTheme"
            android:windowSoftInputMode="adjustResize"  />
        <activity android:name=".SettingsActivity"
            android:label="@string/title_activity_settings"
            android:parentActivityName=".MainActivity"
            android:windowSoftInputMode="adjustResize">
            <meta-data android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
    </application>

</manifest>

Update 2:
I created a completely new app, added my form layout as the main layout, and tested whether the problem was in the layout itself. Turns out it is, as even on this newly created app it doesn't seem to resize.

更新2:我创建了一个全新的应用程序,添加了我的表单布局作为主要布局,并测试了问题是否在布局本身。事实证明,就像这个新创建的应用程序一样,它似乎没有调整大小。

As stated above, the link to the layout can be found Here

如上所述,可以在此处找到布局的链接

Update 3: I managed to make it work on the new application by surrounding the whole layout with a ScrollView. I couldn't replicate the same effect in the original app for some reason... still trying to figure out why.

更新3:我设法通过使用ScrollView包围整个布局使其适用于新应用程序。由于某种原因,我无法在原始应用程序中复制相同的效果...仍在试图找出原因。

6 个解决方案

#1


19

When the soft keyboard appears on the screen, the amount of space available for the application's UI reduces. The system makes decision on how to organize the available space between the application's UI and soft keyboard.

当软键盘出现在屏幕上时,应用程序UI的可用空间量会减少。系统决定如何组织应用程序的UI和软键盘之间的可用空间。

  • If the window content contains ListView, ScrollView, the application's window is resized provided all the content is visible.
  • 如果窗口内容包含ListView,ScrollView,则只要所有内容都可见,应用程序的窗口就会调整大小。
  • If re-sizing is not feasible, pan and scan approach is used, which simply involves scrolling the application's window so that the currently focused view is visible.
  • 如果重新调整大小不可行,则使用平移和扫描方法,其仅涉及滚动应用程序的窗口以使得当前聚焦的视图可见。

Since your layout does not contain any ListView, ScrollView, re-sizing is ruled out.

由于您的布局不包含任何ListView,因此ScrollView会重新调整大小。

The window's root view is a FrameLayout to which you were originally adding LinearLayout. Since LinearLayout does not support scrolling, pan and scan approach is also ruled out. Hence wrapping the layout inside ScrollView solves the scrolling issue.

窗口的根视图是您最初添加LinearLayout的FrameLayout。由于LinearLayout不支持滚动,因此也排除了平移和扫描方法。因此,在ScrollView中包装布局可以解决滚动问题。

You can refer Android Developers blog for more details.

您可以参考Android开发者博客了解更多详情。

Update 1:

更新1:

OP was able to solve the issue, as indicated in this answer. The issue was happening due to one fragment overlaying another fragment after animation and the parent of these Fragment's was a LinearLayout. For overlay purpose, you need to use RelativeLayout or FrameLayout only.

如本回答所示,OP能够解决问题。问题发生的原因是一个片段在动画后覆盖了另一个片段,而这些片段的父片段是一个LinearLayout。出于叠加目的,您只需要使用RelativeLayout或FrameLayout。

更多相关文章

  1. 添加脚本到Android应用程序
  2. 如何使用java RESTful Web服务将通知推送到Android应用程序
  3. android 获取正在运行的应用程序列表
  4. 如何开始为Android开发应用程序? [重复]
  5. 王家林最受欢迎的一站式云计算大数据和移动互联网解决方案课程 V
  6. 当在调试模式下启动时,Android应用程序崩溃。
  7. 嵌套片段不保留其状态
  8. 基于Java的应用程序的GUI测试工具
  9. 为内存密集型应用程序增加JVM最大堆大小

随机推荐

  1. Mssql根据表名获取字段
  2. 这被认为是正常形式的失败吗?
  3. 建议一种有效的查询方式
  4. Code First for Mysql 错误:未为提供程序
  5. sql语句,order by后加参数问题
  6. mybatis中 insert into select 批量生成u
  7. ORA-19909:当进行不完全恢复之后使用open
  8. sql 2005判断某个表或某个表中的列是否存
  9. MySQL中的类Decode用法
  10. 如何优化用于从表复制数据的oracle过程?