当前位置: 首页 > 知识库问答 >
问题:

为什么键盘显示时我的视图没有上滑?

惠洛华
2023-03-14

我正在使用下面的活动布局。

android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.drawerlayout.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.sothree.slidinguppanel.SlidingUpPanelLayout
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        app:panelHeight="0dp"
        app:shadowHeight="0dp"
        app:overlay="true" >

        <RelativeLayout android:id="@+id/rootRelativeLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

            <fragment
                android:id="@+id/location"
                android:name="com.google.android.gms.maps.MapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:layout="@layout/activity_main_map" />

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="?attr/actionBarSize"
                app:theme="@style/toolbarThemeFakeDark"
                android:background="@drawable/trans_toolbar_bg"
                android:layout_margin="16dp"
                android:subtitle="test">

                <ImageView
                    android:id="@+id/wordmark"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:srcCompat="@drawable/wordmarkwhite"
                    android:contentDescription="@string/wordmark" />
            </androidx.appcompat.widget.Toolbar>

            <androidx.appcompat.widget.Toolbar android:id="@+id/timeBar"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:minHeight="?attr/actionBarSize"
                android:background="@drawable/trans_toolbar_bg"
                android:layout_marginBottom="24dp"
                android:layout_alignParentBottom="true" >

                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_marginStart="4dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginBottom="20dp" >
                    <SeekBar
                        android:id="@+id/maxTime"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="32dp"
                        android:progress="100"
                        android:hapticFeedbackEnabled="true"
                        android:layout_alignStart="@+id/timeNumber"
                        style="@style/MapSeekBar"
                        android:thumb="@drawable/map_seekbar_thumb" />

                    <TextView android:id="@+id/timeNumber"
                        android:background="@drawable/map_seekbar_thumb"
                        android:gravity="center"
                        android:layout_width="32dp"
                        android:layout_height="32dp"
                        android:textColor="@color/cpb_grey"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="0dp" />
                </RelativeLayout>
            </androidx.appcompat.widget.Toolbar>

        </RelativeLayout>

        <!--- Where all the fragments live -->
        <FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:elevation="20dp"/>
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>

    <fragment android:name="com.myapp.FragmentLeftPanel"
        android:id="@+id/left_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:maxWidth="400dp"
        />

    <fragment android:name="com.myapp.FragmentFilterPanel"
        android:id="@+id/right_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        />
</androidx.drawerlayout.widget.DrawerLayout>

<FrameLayout android:id="@+id/cluster_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="20dp"/>
<FrameLayout android:id="@+id/cluster_event_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="20dp"/>
<FrameLayout android:id="@+id/create_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="20dp"/>

和下面的片段布局。

片段被加载到活动布局的“fragment_container”节点中。

<View android:id="@+id/backgroundColor"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/app_light_background"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent">

        <FrameLayout
            android:id="@+id/commentFrame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="40dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="4dp"
            android:layout_marginRight="16dp"
            android:background="@color/app_light_background" >

            <LinearLayout
                android:id="@+id/textBox"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="start|bottom|end"
                android:measureWithLargestChild="true"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/attachButton"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:elevation="1dp"
                    android:paddingStart="1dp"
                    android:paddingEnd="10dp"
                    android:contentDescription="Attach Picture"
                    app:srcCompat="@android:drawable/ic_menu_camera" />

                <EditText
                    android:id="@+id/commentBox"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="start|center_vertical"
                    android:layout_weight="1"
                    android:ems="10"
                    android:hint="Comment"
                    android:inputType="text|textCapSentences|textMultiLine"
                    android:maxHeight="70dp"
                    android:autofillHints=""
                    android:textColor="@color/app_light_primary_text" />

                <ImageView
                    android:id="@+id/sendButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:clickable="true"
                    android:focusable="true"
                    android:paddingStart="24dp"
                    android:paddingTop="8dp"
                    android:paddingEnd="8dp"
                    android:paddingBottom="8dp"
                    android:contentDescription="Post Comment"
                    android:tint="@color/app_light_primary_frame"
                    android:src="@drawable/ic_send_grey600_36dp" />
            </LinearLayout>

        </FrameLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/commentFrame"
            android:clickable="true"
            android:focusable="true"
            android:gravity="center_horizontal"
            android:orientation="vertical">

            <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
                android:id="@+id/commentRefresh"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <ListView
                    android:id="@+id/commentList"
                    android:layout_width="fill_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:background="@color/app_light_background"
                    android:clickable="true"
                    android:focusable="true" />
            </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
        </LinearLayout>

        <View
            android:layout_width="fill_parent"
            android:layout_height="@dimen/shadow_height"
            android:layout_above="@+id/commentFrame"
            android:background="@drawable/above_shadow" />

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            app:theme="@style/toolbarThemeFakeDark">
        </androidx.appcompat.widget.Toolbar>

    </RelativeLayout>

<View android:id="@+id/backPart"
    android:layout_width="match_parent"
    android:layout_height="100dip"
    android:clickable="true"
    android:focusable="true"
    android:visibility="gone" />

<View android:id="@+id/dragPart"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:focusable="true"
    android:layout_below="@+id/backPart"
    android:layout_alignParentStart="true" />

我的问题是片段中的“commentbox”字段。当你点击它时,虚拟键盘会出现在碎片内容的下半部分上方,而不是将内容向上推。因此在键入时无法看到文本字段。

我几天来一直在搜索和尝试推荐,比如使用“Android:Windowsoftinputmode=AdjustPan”或某个变种。但都没有起到任何作用。

在这种情况下,是什么阻止了键盘上推活动的内容呢?

共有1个答案

马才
2023-03-14

android:Windowsoftinputmode=“StatealWayShiddenAdjustreSize”添加到清单文件中的活动

然后在rootLayout(而不是EditText)中添加android:fitsSystemWindows=“true”

 类似资料:
  • 您将自动执行著名的歌曲“墙上的99瓶XXX”。你将打印这首歌所有99个诗句的歌词。用循环!如果你不知道歌词,用谷歌查一下。 该方案应: a.如果他们不到21岁,或者他们喜欢苏打水,那么歌词是“墙上有99瓶苏打水” B.如果他们超过21岁,那么是“99瓶啤酒” 您必须使用WHILE循环,并且counter变量必须是print语句的一部分! 所以第一节是: 99瓶苏打水挂在墙上 墙上有98瓶苏打水 最

  • 我是JProfiler的新手。我创建了一个非常简单的测试应用程序。这是一个带有main方法的Main.java: 注意,我暂停直到按键。通过这种方式,我确信主作用域在我按下一个键之前不会结束,所以我希望e存在并且不会被垃圾收集(如果这个假设不正确,请纠正我)。示例类: 我使用JProfiler Eclipse插件启动上述应用程序。我创建了一个基于完整仪器配置文件的会话;我已经删除了Java EE和

  • 这应该是一个相对简单的问题,但它让我发疯。我正在尝试在JavaFX中创建扫雷器(主要用于练习),但我甚至无法显示一个简单的矩形。我以前运行过一次游戏,但我试图使游戏更加抽象,因此更容易编码,但我遇到了不显示任何问题。 我消除了所有无关的代码,使其尽可能简单。我基本上是在尝试创建一个名为Box的具有特定颜色和大小的矩形,将框添加到窗格中,并显示窗格。为了使Box成为可以在窗格上显示的节点,我使Box

  • 父组件相关代码 html js 子组件 复现步骤: 第一次打开弹框: 时间选择器显示的是当前时间 更改时间选择器的时间之后关闭弹框 第二次打开弹框,显示时间是之前弹框里面时间选择的时间,而不是当前时间?

  • 以下项目是从一个在线课程中逐字复制的。它应该显示一个ListView,但什么也不显示。我是一个全新的Android工作室,这只是我在里面的第二个项目。这里有5个文件,我将在下面显示每个文件的内容。我只需要另一双或两双眼睛来发现问题,因为我是“虫子盲”。任何帮助都将不胜感激。 activity_main.xml OurAdapter.java 包com.example.tadhg.uiuxAdapt

  • 我有一个SherlockFragmentActivity和一个位于TabManager中的Sherlock Fragment。在这个片段中,我在LinearLayout中有单选按钮、复选框、按钮和编辑文本。按下编辑文本时,键盘有时不响应。 在2.1 AVD中,键盘响应不一致,在4.0 AVD中,键盘根本没有响应,而在设备上,键盘响应不一致。有时按下其他对象会激活显示键盘的功能。 以下是编辑文本的X