【问题标题】:ScrollView not scrolll when open soft keyboard打开软键盘时ScrollView不滚动
【发布时间】:2015-10-06 21:09:08
【问题描述】:

我想打开软键盘并在键盘上方滚动编辑文本。但它必须在scrollView中。现在我有错误的结果: video

我不想滚动顶部视图。我只想滚动编辑文本。

我使用这个主题:

<style name="Theme.TransparencyDemo" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
    </style>

编辑:

video sample

布局:

<?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"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"
              android:weightSum="1"
                android:background="#142e06">


    <TextView
        android:layout_width="100dp"
        android:layout_height="30dp"
        android:text="New Text"
        android:id="@+id/textView"
        android:background="#ff4018"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"/>

    <EditText
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="150dp"/>

</RelativeLayout>

【问题讨论】:

  • 你在 AndroidManifest.xml 中为你的 Activity 设置了 android:windowSoftInputMode="adjustPan" 吗?
  • 我试过了,没用
  • set android:windowSoftInputMode="adjustResize" 也没用?
  • 我也试过了,没用

标签: android android-softkeyboard android-scrollview


【解决方案1】:

使用 LinearLayout 而不是 Relative 并将这一行添加到清单中的活动标记

 android:windowSoftInputMode="adjustPan"

【讨论】:

  • 我想调整调整大小的行为,但没有任何建议?
【解决方案2】:

在你的布局中添加这个android:fitsSystemWindows="true"like this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <include layout="@layout/toolbar" />
     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"      
        ndroid:fitsSystemWindows="true"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">


        <!-- Your Content here -->


    </LinearLayout>
</RelativeLayout>

这样就可以了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-03
    • 2018-12-08
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    • 2020-12-06
    • 2012-07-01
    相关资源
    最近更新 更多