键盘打开时片段布局无法完全滚动

时间:2020-09-16 08:44:24

标签: android android-fragments android-scrollview window-soft-input-mode

我希望片段中的布局能够完全滚动并在键盘打开时将其放置在软键盘上方。但是问题是当用户单击键盘时,布局甚至没有滚动。它覆盖了布局的一部分。

我已经尝试了许多SO线程,但是似乎没有一个工作。

这是活动布局:

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

    <data>

        <import type="android.view.View" />

        <variable
            name="viewModel"
            type="com.abc.viewModel" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".home.HomeActivity">

        <com.google.android.material.card.MaterialCardView
            android:id="@+id/taskBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_minus10sdp"
            android:background="@android:color/white"
            app:cardCornerRadius="@dimen/_5sdp">

            
        </com.google.android.material.card.MaterialCardView>

        <LinearLayout
            android:id="@+id/appbar_practice"
            android:visibility="gone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimaryDark"
            android:gravity="center_horizontal"
            android:orientation="horizontal"
            android:paddingTop="@dimen/_10sdp">

            
        </LinearLayout>

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>

</layout>

这是片段布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:isScrollContainer="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:animateLayoutChanges="true"
    android:background="@drawable/ic_bg_splash"
    android:fillViewport="true"
    android:paddingBottom="@dimen/_10sdp">
    
    <LinearLayout
        android:id="@+id/cardview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2">

            <ImageButton
                android:id="@+id/previous"
                android:layout_width="@dimen/_30sdp"
                android:layout_height="@dimen/_30sdp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="@dimen/_20sdp"
                android:background="@drawable/left"
                android:padding="@dimen/_5sdp" />
        </RelativeLayout>        

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2">

            <ImageButton
                android:id="@+id/next"
                android:layout_width="@dimen/_30sdp"
                android:layout_height="@dimen/_30sdp"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="@dimen/_20sdp"
                android:background="@drawable/right" />

        </RelativeLayout>

    </LinearLayout>
</ScrollView>

清单:

 <activity android:name=".home.MainActivity"
            android:screenOrientation="landscape"
            android:theme="@style/MaterialThemeHome"></activity>

0 个答案:

没有答案