滚动不在NestedScrollView时尝试从与点击事件的看法滚动工作 [英] Scroll doesn't work in NestedScrollView when try to scroll from views with click events

查看:261
本文介绍了滚动不在NestedScrollView时尝试从与点击事件的看法滚动工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是NestedScrollView的布局,并在尝试使用新的CoordinatorLayout从为CollapsingToolbarLayout设计支持库。

I'm using a NestedScrollView in a layout, and am attempting to use the new CoordinatorLayout from the design support library for CollapsingToolbarLayout.

我的布局文件看起来是这样的:

My layout file looks like this:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"

            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
            <!--            app:expandedTitleMarginEnd="64dp"-->
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:scaleType="centerCrop"
                android:src="@drawable/image_load_default_big" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/anim_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
            </android.support.v7.widget.Toolbar>

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

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

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nestedScrollVw"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|enterAlways"
        android:fitsSystemWindows="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="false"
            android:fitsSystemWindows="true">

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

                <Button
                    android:id="@+id/changePasswordExpand"
                    android:layout_width="match_parent"
                    android:layout_height="55dp"
                    android:background="@drawable/back_img"
                    android:text="Change Your Password"
                    android:textColor="@color/white"
                    android:textStyle="bold" />
            </LinearLayout>


            <LinearLayout
                android:id="@+id/changePasswordContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/changePasswordButtonContainer"
                android:layout_centerInParent="true"
                android:orientation="vertical"
                android:padding="10dp">


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:text="Edit Your Password"
                    android:textColor="@color/orange" />

                <EditText
                    android:id="@+id/etUserName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/edittext_default_bg"
                    android:drawableLeft="@drawable/password_icon"
                    android:drawableRight="@drawable/tick"
                    android:hint=" Old Password"
                    android:padding="12dp"
                    android:password="true"
                    android:textColorHint="#b5b5b5" />

                <EditText
                    android:id="@+id/etPass"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/edittext_default_bg"
                    android:drawableLeft="@drawable/password_icon"
                    android:drawableRight="@drawable/cross"
                    android:hint=" New Password"
                    android:padding="12dp"
                    android:password="true"
                    android:textColorHint="#b5b5b5" />

                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingBottom="20dp"
                    android:paddingTop="20dp"
                    android:text="show password" />

                <Button
                    android:id="@+id/btnSingIn"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="4dp"
                    android:background="@drawable/login_button_background"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp"
                    android:text="Done"
                    android:textColor="@color/white"
                    android:textStyle="bold" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/dealerToDealerContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/changePasswordContainer"
                android:orientation="vertical">

                <Button
                    android:id="@+id/dealerToDealerExpand"
                    android:layout_width="match_parent"
                    android:layout_height="55dp"
                    android:background="@drawable/back_img"
                    android:text="Dealer To Dealer Platform No"
                    android:textColor="@color/white"
                    android:textStyle="bold" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/dealerToDealerContainer"
                android:layout_centerInParent="true"
                android:orientation="vertical"
                android:padding="10dp">


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:text="Edit Number"
                    android:textColor="@color/orange" />

                <EditText
                    android:id="@+id/dealerToDealerNo"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/edittext_default_bg"
                    android:drawableLeft="@drawable/password_icon"
                    android:drawableRight="@drawable/tick"
                    android:hint=" 56546789"
                    android:padding="12dp"
                    android:password="true"
                    android:textColorHint="#b5b5b5" />

                <Button
                    android:id="@+id/dealerToDealerNoDone"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="4dp"
                    android:background="@drawable/login_button_background"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp"
                    android:text="Done"
                    android:textColor="@color/white"
                    android:textStyle="bold" />
            </LinearLayout>

        </RelativeLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

当我尝试滚动,有时这是行不通的。 原因是,布局与点击事件等要素消耗的触摸事件。 基本上的EditText,单选按钮,按钮消耗触摸事件。 任何建议,以解决这个问题?

When i try to scroll, sometimes it doesn't work. reason for this is, other elements of layout with click events are consuming the touch event. Basically EditText, RadioButton, Button are consuming touch events. Any Suggestions to solve this problem ?

推荐答案

我有同样的问题。这种事只有当NestedScrollView内容高度小于设备屏幕的高度。因此,解决方法是使用 setMinimumHeight(..)方法,在你的 NestedScrollView ,使其调整到屏幕视图身高:

I had the same problem. It happens only when NestedScrollView content height is less than height of device screen. So the workaround is to use setMinimumHeight(..) method for the view inside your NestedScrollView to make it resize to screen height:

DisplayMetrics displaymetrics = new DisplayMetrics();
getBaseActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int screenHeight = displaymetrics.heightPixels;

int actionBarHeight = 0;
TypedValue tv = new TypedValue();
if (getBaseActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
    actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
}

view.setMinimumHeight(screenHeight - actionBarHeight);

其中,视图 RelativeLayout的

它工作正常脱颖而出我。希望它可以帮助你。

It works fine fore me. Hope it helps you

这篇关于滚动不在NestedScrollView时尝试从与点击事件的看法滚动工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆