【问题标题】:Complete Layout moves upwards if Soft Keyboard is shown如果显示软键盘,则完整布局向上移动
【发布时间】:2019-08-20 14:51:28
【问题描述】:

有没有办法只在键盘上方移动某个布局而让其余部分保持不变?我曾尝试使用android:windowSoftInputMode="stateVisible|adjustResize" 并使用滚动视图,但它们都不起作用。

如果显示键盘,这就是它的外观,但我只需将键盘上方底部的注释布局移动,其余部分保持原样。

我的代码如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/colorWhite"
          android:orientation="vertical">

<ScrollView
        android:layout_width="match_parent"
        android:layout_weight="20"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView">

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

        <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/colorTransparent" android:id="@+id/toolbar_comments">

            <ImageButton
                    android:layout_width="50dp"
                    android:layout_height="match_parent"
                    android:src="@drawable/ic_arrow_back"
                    android:tint="@android:color/black"
                    android:background="@color/colorTransparent"   android:id="@+id/back_btn_comments"/>

            <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textAlignment="center"
                    android:gravity="center"
                    android:textSize="20sp"
                    android:textColor="@android:color/black"
                    android:text="Kommentare"/>
            <View
                    android:layout_width="match_parent"
                    android:layout_height="0.5dp"
                    android:layout_alignParentBottom="true"
                    android:background="@color/colorFont"/>

        </RelativeLayout>

        <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/comments_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/toolbar_comments"
                android:layout_marginTop="5dp">

        </androidx.recyclerview.widget.RecyclerView>
    </RelativeLayout>
</ScrollView>

<include
        layout="@layout/message_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:layout_marginTop="5dp"/>
</LinearLayout>

感谢您的帮助!

【问题讨论】:

标签: android kotlin


【解决方案1】:

试试下面的代码,它对我有用

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorBackGround"
            android:orientation="vertical">

           //toolbar code here

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:isScrollContainer="true"
                android:layout_weight="1">

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recyclerMessages"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:clipToPadding="false"
                    android:padding="@dimen/_10sdp" />

            </RelativeLayout>


           //comment layout code here

        </LinearLayout>

并在清单中添加以下类型

android:windowSoftInputMode="adjustUnspecified"

【讨论】:

    猜你喜欢
    • 2010-12-30
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 2015-11-01
    • 2017-04-20
    • 2011-04-16
    • 1970-01-01
    相关资源
    最近更新 更多