【问题标题】:Scrollview not scrolling in Android (AdjustPan)滚动视图在 Android 中不滚动(AdjustPan)
【发布时间】:2017-12-07 20:07:52
【问题描述】:

这是我的 scrollView xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/myCoordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@drawable/gradient_toolbar"
        android:clickable="true"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/u_back_action"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="8dp"
            android:padding="4dp"
            android:src="@mipmap/arrow_back_blue" />


        <TextView
            android:id="@+id/headerTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/u_my_page"
            android:textColor="#ffffff"
            android:textSize="16dp" />

        <TextView
            android:id="@+id/my_profile_edit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="8dp"
            android:gravity="center"
            android:padding="8dp"

            android:singleLine="true"
            android:text="@string/u_save"
            android:textColor="#ffffff"
            android:textSize="14dp"
            android:visibility="gone" />


    </RelativeLayout>


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


<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:orientation="vertical"

        >


        <LinearLayout
            android:id="@+id/user_header_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:gravity="center_vertical"
            android:orientation="vertical">



            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/u_user_fullname"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:maxLines="1"
                    android:singleLine="true"
                    android:textColor="#4d4d4d"
                    android:textSize="@dimen/u_common_text_size"

                    />
            </LinearLayout>


        </LinearLayout>


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true">


            <LinearLayout
                android:id="@+id/container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/personal_settings"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:layout_marginTop="30dp"
                    android:text="@string/u_personal_settings_txt"
                    android:textColor="#4d4d4d"
                    android:textSize="16dp" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#cccccc" />


                <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="16dp"
                    android:background="@drawable/selector_edittext_action"
                    android:textColor="#4d4d4d"

                    android:textColorHint="#b3b3b3">

                    <android.support.design.widget.TextInputEditText
                        android:id="@+id/first_name_lat"
                        android:layout_width="match_parent"
                        android:layout_height="48dp"
                        android:background="@null"
                        android:hint="@string/u_first_name_lat"
                        android:imeOptions="actionNext"

                        android:inputType="textNoSuggestions"
                        android:textColor="#4d4d4d"

                        android:textColorHint="#b3b3b3"
                        android:textCursorDrawable="@null"
                        android:textSize="16dp"
                        app:backgroundTint="@android:color/white" />
                </android.support.design.widget.TextInputLayout>


                <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="16dp"
                    android:background="@drawable/selector_edittext_action"
                    android:textColor="#4d4d4d"

                    android:textColorHint="#b3b3b3">

                    <android.support.design.widget.TextInputEditText
                        android:id="@+id/last_name_lat"
                        android:layout_width="match_parent"
                        android:layout_height="48dp"
                        android:background="@null"
                        android:hint="@string/u_last_name_lat"
                        android:imeOptions="actionNext"

                        android:inputType="textNoSuggestions"
                        android:textColor="#4d4d4d"

                        android:textColorHint="#b3b3b3"
                        android:textCursorDrawable="@null"
                        android:textSize="16dp"
                        app:backgroundTint="@android:color/white" />
                </android.support.design.widget.TextInputLayout>


                <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="16dp"
                    android:background="@drawable/selector_edittext_action"
                    android:textColor="#4d4d4d"

                    android:textColorHint="#b3b3b3">

                    <android.support.design.widget.TextInputEditText
                        android:id="@+id/u_address"
                        android:layout_width="match_parent"
                        android:layout_height="48dp"
                        android:background="@null"
                        android:hint="@string/u_address"
                        android:imeOptions="actionNext"

                        android:inputType="textNoSuggestions"
                        android:textColor="#4d4d4d"

                        android:textColorHint="#b3b3b3"
                        android:textCursorDrawable="@null"
                        android:textSize="16dp"
                        app:backgroundTint="@android:color/white" />
                </android.support.design.widget.TextInputLayout>


                <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="16dp"
                    android:background="@drawable/selector_edittext_action"
                    android:textColor="#4d4d4d"

                    android:textColorHint="#b3b3b3">

                    <android.support.design.widget.TextInputEditText
                        android:id="@+id/u_gender"
                        android:layout_width="match_parent"
                        android:layout_height="48dp"
                        android:background="@null"
                        android:hint="@string/u_gender"
                        android:imeOptions="actionNext"

                        android:inputType="textNoSuggestions"
                        android:textColor="#4d4d4d"

                        android:textColorHint="#b3b3b3"
                        android:textCursorDrawable="@null"
                        android:textSize="16dp"
                        app:backgroundTint="@android:color/white" />
                </android.support.design.widget.TextInputLayout>


            </LinearLayout>

        </ScrollView>
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

在我的活动中,SoftInputMode 是adjustNothing。

正如我所说,我的滚动视图不起作用。我搜索我的问题,一个解决方案是更改 adjustResize,但我不想要这个解决方案,因为我的 AppBarLayout 布局向上移动。

我的问题是,现在是否可以移动滚动视图(adjustNothing)。当键盘显示时,我无法显示我的最后一个编辑文本。 或者,如果我使用 adjustResize 或 adjustPan 是否可以在我的 xml 中禁用上移 AppBarLayout 布局? 谢谢大家

【问题讨论】:

  • 我面临同样的问题。您能分享一下您是如何解决这个问题的吗?

标签: android android-edittext android-scrollview


【解决方案1】:

这里有一个解决方案

在 NestedScrollView 的子布局中添加这一行

android:descendantFocusability="afterDescendants"

和清单文件

android:windowSoftInputMode="adjustResize"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多