【问题标题】:Set scroll the screen moving upside when open keyboard in android在android中打开键盘时设置滚动屏幕向上移动
【发布时间】:2022-01-19 09:41:17
【问题描述】:

我正在努力在键盘打开时执行滚动!出现键盘时,我的屏幕没有向上滚动。当键盘出现时,我希望我的屏幕需要向上滚动。以及它向我展示了布局的底部。请提出满足该要求的指导方针。有没有其他方法可以做到这一点?.....提前谢谢。

我已经尝试了很多 - 在清单文件中放那个 sn-p :

android:windowSoftInputMode="adjustPan" 
android:windowSoftInputMode="adjustResize|stateHidden"

在 XML 文件中添加属性:

 <ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/appBarLayout"
    android:fillViewport="true"
    android:fitsSystemWindows="true"
    android:scrollbars="none">

但是,这也不起作用。请提出任何适当的解决方案。

这是我的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".work.CreateClassActivity">
 <com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="@color/ColorsWhite"
    android:theme="@style/AppTheme.AppBarOverlay">
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:weightSum="1"
        app:popupTheme="@style/AppTheme.PopupOverlay">
        <RelativeLayout
            android:id="@+id/relativeLayoutLogo"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1.00"
            android:visibility="visible">
            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_centerVertical="true"
                android:text="@string/create_class"
                android:textColor="@color/colorTextDarkBlue"
                android:textSize="20sp"
                android:textStyle="bold" />
        </RelativeLayout>
    </androidx.appcompat.widget.Toolbar>
 </com.google.android.material.appbar.AppBarLayout>
 <ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/appBarLayout"
    android:fillViewport="true"
    android:fitsSystemWindows="true"
    android:scrollbars="none">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:weightSum="5">          
    </LinearLayout>
 </ScrollView>  
</RelativeLayout>

这是我的清单文件 sn-p:

<activity
  android:name=".work.CreateClassActivity"
  android:launchMode="singleTask"
  android:screenOrientation="landscape"
  android:windowSoftInputMode="adjustResize|stateHidden"
  android:theme="@style/AppTheme.NoActionBar" />

【问题讨论】:

    标签: android android-layout scrollview android-softkeyboard


    【解决方案1】:

    您只需要在AndroidManifest.xml 中的相应活动上使用adjustPan 而不是adjustResize。你只需要像这样调整它。

    <activity
      android:name=".work.CreateClassActivity"
      android:launchMode="singleTask"
      android:screenOrientation="landscape"
      android:windowSoftInputMode="adjustPan"
      android:theme="@style/AppTheme.NoActionBar" />
    

    【讨论】:

      【解决方案2】:

      解决方案 - 步骤 - 1:在清单文件中将该行放入您的特定活动中: android:windowSoftInputMode="adjustResize"

      Step - 2 : In java file and in onCreate() put that line :
                  getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);     
                  
      Step - 3 : Before run the project - first clean project and uninstall previous apk.
      
      Step - 4 : Run the project and you will get that desired result.
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-08-14
        • 2011-12-16
        • 1970-01-01
        • 2016-04-19
        • 2016-02-04
        • 2021-09-16
        • 1970-01-01
        相关资源
        最近更新 更多