【问题标题】:Scrolling not triggered when keypad is showing in NesetedScrollViewNestedScrollView 中显示键盘时未触发滚动
【发布时间】:2016-02-04 15:40:48
【问题描述】:

我有以下布局,基本上显示两个编辑文本

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    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"
    android:fillViewport="true"
    android:layout_gravity="fill_vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="global.sti.attendance.LogInActivity"
    tools:showIn="@layout/activity_log_in">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:orientation="vertical"
        android:paddingTop="150dp"
        android:paddingBottom="50dp">
        <EditText
            style="@style/TextField"
            android:id="@+id/userNameET"
            android:hint="Enter username"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableStart="@drawable/ic_user"
            android:background="@drawable/custom_textfield"/>
        <EditText
            style="@style/TextField"
            android:id="@+id/passwordET"
            android:hint="Enter password"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableStart="@drawable/ic_lock"
            android:background="@drawable/custom_textfield"/>
        <Button
            style="@style/Button"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Log-in"
            android:id="@+id/loginButton"
            android:layout_gravity="center_horizontal"
            android:width="180dp" />
        <Button
            style="@style/Button"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SIGN-UP!"
            android:id="@+id/signUpButton"
            android:layout_gravity="center_horizontal"
            android:width="180dp" />
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

这是我的activity_log_in.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context="global.sti.attendance.LogInActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_log_in" />

</android.support.design.widget.CoordinatorLayout>

这是我的 TextField 样式:

<style name="TextField">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:textCursorDrawable">@null</item>
    <item name="android:paddingTop">10dp</item>
    <item name="android:paddingBottom">10dp</item>
    <item name="android:drawablePadding">10dp</item>
    <item name="android:paddingLeft">10dp</item>
    <item name="android:paddingRight">10dp</item>
    <item name="android:height">40dp</item>
</style>

问题是,当我单击其中一个 editTexts 并显示键盘时,它会阻止我的视图,我希望 NestedScrollView 将允许我向上滚动,但它不会。

似乎是什么问题?谢谢!

【问题讨论】:

  • 顺便说一句,您在示例中缺少结束 标记。
  • 我正在测试你的布局,我可以毫无问题地滚动,你能发布你的 activity_log_in.xml 和“@style/TextField”样式吗?
  • 也可能只是您拥有的固定填充:android:paddingTop="150dp"
  • @Evin1_ 好的,我发布我的 activity_log_in 并注意我有 只是不小心忽略了它。
  • @Evin1_ 我在我的问题上添加了您的请求。请参见。谢谢。

标签: android android-design-library


【解决方案1】:

将此添加到 AndroidManifest.xml 中的活动中:

android:windowSoftInputMode="stateVisible|adjustResize"

例子:

<activity
    android:name=".LogInActivity"
    android:windowSoftInputMode="stateVisible|adjustResize">
    <!-- Intent-filters if any -->
</activity>

【讨论】:

  • 好的,我试试这个,如果可行,稍后再回复您。谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-01-21
  • 2016-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-17
  • 2014-08-23
  • 1970-01-01
相关资源
最近更新 更多