ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android – 键盘启动时的CardView滚动行为

2019-05-28 10:12:09  阅读:238  来源: 互联网

标签:android android-scrollview android-cardview


我们的应用程序的主要内容是CardView的RecylerView.对于注册,我们需要的不仅仅是用户名/密码来创建帐户,因此我们决定在注册后使用CardView的注册流程来匹配用户体验.

要做到这一点,我有一个Activity从底部动画片段,从顶部动画片段以模拟滚动.当用户输入数据并且在前进之后点击时发生这种虚假滚动.除了一个案例之外,这很有效.当我们有一个EditText用于输入时,键盘会出现并覆盖屏幕底部的“下一个”按钮.

在我们的用户测试中,我们注意到很大比例的用户试图将卡片向上滚动以转到下一个按钮而不是解除键盘.

我花了很多时间试图让CardView向上滚动以显示按钮并且我没有想法并且正在寻找新的想法.

注册活动布局仅包含我将Fragments加载到的FrameLayout.每个加载的片段都有一个用于根布局的CardView.

在清单中,我已将活动的windowsSoftInputMode设置为adjustResize,adjustPan收效甚微.

activity_signup.xml

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/signUpContent"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

简化了fragment_enter_code.xml

<android.support.v7.widget.CardView
style="@style/CardViewStyle.SignUp"
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="wrap_content"
app:cardCornerRadius="25dp"
app:cardElevation="2dp"
app:cardUseCompatPadding="true"
app:contentPadding="8dp">

        <EditText
             android:id="@+id/codeEditText"
             style="@style/HintedEditText"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="Code"
             android:inputType="text"/>

        <Button
            style="@style/NextButton"
            android:id="@+id/nextButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:enabled="false"
            android:text="@string/next"/>

</android.support.v7.widget.CardView>

当我尝试将CardView放在ScrollView中的cardview布局(使用fillViewport为true)时,我得到一个滚动条,但是卡片没有滚动,卡片视图布局搞砸了.

有谁知道windowSoftInputMode足以让我指向正确的方向?或者CardView是不是要在设计用于容纳它们的Container之外滚动?

感觉就像解决这个问题的方法是操纵活动的视图而不是片段.

解决方法:

我最终创建了一个新的应用程序来解决这个问题,并注意到如果我的布局不包含其根布局为ScrollView的CardView,它不会滚动,除非活动windowSoftInputMode设置为adjustResize然后它会滚动.

然后,我使用< ScrollView>< CardView>< content ...>< / CardView>< / ScrollView>制作了布局.并且CardView的大小始终是卡的默认行大小,并且不匹配match_parent.我在ScrollView上用fillViewPort =“true”解决了这个问题,但是当键盘出现时它不会滚动.

事实证明秘诀就是在CardView和ScrollView之间放置一个FrameLayout(或任何其他布局).

您仍然需要考虑布局的大小调整,以防止您的视图元素没有相互堆叠但是一旦您这样做,您现在可以获得软键盘上方的视图以滚动并使用CardView访问UI的其余部分.

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:cardCornerRadius="35dp"
            app:cardElevation="2dp"
            app:cardUseCompatPadding="true"
            app:contentPadding="8dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/image"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:src="@drawable/common_ic_googleplayservices"/>

                <EditText
                    android:id="@+id/input"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="50dp"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="20dp"
                    android:layout_below="@id/image"
                    android:hint="Input"
                    android:inputType="text"/>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_below="@id/input"
                    android:orientation="vertical"
                    android:gravity="bottom|center_horizontal">

                    <Button
                        android:id="@+id/nextButton"
                        android:layout_width="match_parent"
                        android:layout_height="48dp"
                        android:layout_marginLeft="20dp"
                        android:layout_marginRight="20dp"
                        android:enabled="false"
                        android:text="Next"/>

                </LinearLayout>

            </RelativeLayout>

        </android.support.v7.widget.CardView>

    </FrameLayout>

</ScrollView>

标签:android,android-scrollview,android-cardview
来源: https://codeday.me/bug/20190528/1170068.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有