与片段活动键盘打开时不调整 [英] Activity with fragments does not resize when the keyboard opens

查看:198
本文介绍了与片段活动键盘打开时不调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的主要活动有一个 RelativeLayout的有2名儿童:

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


  • 的ImageView 充当背景

  • A 的LinearLayout 有2个片段容器

  • An ImageView which serves as the background
  • A LinearLayout that has 2 fragment containers
<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>

容器简单地表明,不改变片段。结果
然而,集装箱B就掌握着根据用户点击,它改变一个片段。

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

2的方式容器B内的变化:

Container B changes in 2 ways:


  • 可以(从约70%的高度为全高)展开。

  • 它改变了碎片。

其中的片段容器B能容纳的是一种形式,它包含的EditText 和其他视图。

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

我的问题是,我不能让活动来调整,当键盘打开。结果
我在manifest文件中设置 adjustResize 和我的主题是不是一个全屏的主题(这显然是对这一问题的原因)。我也尝试过编辑视图,添加 ScrollViews 但是绝对没有奏效。

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.

我使用的是这项活动的主题是光的主题从程序兼容性库黑暗动作条。我只是编辑的主题,以允许叠加动作条。这是的不可以我已经试图消除这些修改都无济于事。问题

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.

下面就以表格布局的链接

Here's a link to the form layout

TL; DR adjustResize / adjustPan 不为我工作。搜查,尝试了各种解决方案,毫无效果。我的问题是;究竟是什么原因在我的情况?

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?

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

更新2:结果
我创建了一个全新的应用程序,添加我的表格布局为主要布局,并测试问题是否是布局本身。原来是这样,因为即使在这个新创建的应用程序似乎并没有调整。

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.

如上所述,链接的布局可以发现 这里

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

更新3:
我设法围绕整个布局以滚动型,使其在新的应用程序。我无法复制在原来的应用程序由于某种原因,同样的效果......仍然试图找出原因。

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.

推荐答案

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

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.


  • 如果窗口内容包含的ListView 滚动型,被调整应用程序的窗口中提供的所有内容是可见的。

  • 如果大小调整是行不通的,平移和扫描办法使用,它只是涉及滚动应用程序的窗口,使当前重点的看法是可见的。

  • If the window content contains ListView, ScrollView, the application's window is resized provided all the content is visible.
  • 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.

由于您的布局不包含任何的ListView 滚动型,调整大小是排除了。

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

该窗口的根视图是一个的FrameLayout 来,你最初加入的LinearLayout 。由于的LinearLayout 不支持滚动,平移和扫描方法也排除了。因此,包裹里面的布置滚动型解决滚动问题。

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.

您可以参考<一个href=\"http://android-developers.blogspot.in/2009/04/updating-applications-for-on-screen.html\">Android开发者博客了解更多详情。

You can refer Android Developers blog for more details.

更新1:

OP能够解决问题,因为在这个回答。这个问题是发生因一个片段覆盖动画完成后,另一片段以及这些父片段的是的LinearLayout 。对于覆盖的目的,你需要使用 RelativeLayout的的FrameLayout

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.

这篇关于与片段活动键盘打开时不调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆