首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NestedScrollView中的NestedScrollview未滚动

NestedScrollView中的NestedScrollview未滚动
EN

Stack Overflow用户
提问于 2018-09-03 01:37:07
回答 1查看 1.3K关注 0票数 2

我知道这个问题经常出现,但我尝试了几乎所有的解决方案,即使是神奇的解决方案显然对我也不起作用!:(家长是NestedScrollview,孩子中有另一个NestedScrollview)

代码语言:javascript
复制
    parent.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            Log.v(TAG,"PARENT TOUCH");
            child.getParent().requestDisallowInterceptTouchEvent(false);
            return false;
        }
    });

    child.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event)
        {
            Log.v(TAG,"CHILD TOUCH");
            // Disallow the touch request for parent scroll on touch of child view
            v.getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });

在Logcat上,我得到了“父母接触”和“孩子接触”,但Chidl不滚动!奇怪的是,这个解决方案和其他解决方案适用于其他人,而不是我

这是我的xml结构:(PS:我很乐意尝试您的解决方案)(编辑后

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">
       <NestedScrollView
            android:layout_width="match_parent"
            android:id="@+id/parentscrollview"
            android:layout_height="wrap_content">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">


            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_marginTop="20dp"
                android:textSize="15sp"
                android:layout_height="wrap_content"
                android:text="txt" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="txt2"
                android:textSize="15sp"
                android:layout_below="@+id/textView"
                android:id="@+id/textView2"
                />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text=""
                android:textSize="15sp"
                android:layout_below="@+id/textView2"
                android:id="@+id/textView4"
                />


            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:layout_below="@+id/textView4"
                android:id="@+id/autocainatiner"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="6dp"
                    android:textSize="15sp"
                    android:layout_marginTop="20dp"
                    android:textAllCaps="true"
                    android:text="Please Add/chose the observed clinical features :"
                    />

                <com.mycardboarddreams.autocompletebubbletext.MultiSelectEditText
                    android:id="@+id/auto_text_complete"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/black"
                    android:textStyle="bold"
                    android:padding="5dp"
                    android:background="#FFEEEEEE"/>

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


                <Button
                    android:id="@+id/btnPlanet"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:onClick="blahblah"
                    android:text="Enter" />
                </RelativeLayout>


            </LinearLayout>

            <NestedScrollView
                android:layout_width="match_parent"
                android:id="@+id/scrollframe"
                android:layout_below="@+id/autocainatiner"
                android:fillViewport="true"
                android:layout_height="200dp">
                <FrameLayout
                    android:id="@+id/auto_list_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/colorPrimaryDark"/>
            </NestedScrollView>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/scrollframe"
                android:orientation="vertical"
                >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="40dp"
                    android:textSize="16sp"
                    android:textAllCaps="true"
                    android:textStyle="bold"
                    android:gravity="center_horizontal"
                    android:text="Suggested Diganosi list (Please Click on suggested diseases for more infos)"
                    android:id="@+id/textView3"
                    />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="15sp"
                    android:text="Suggested Diganosi list (Please Click on suggested diseases for more infos)"
                    android:layout_marginTop="25dp"
                    android:textAllCaps="true"
                    android:id="@+id/diagnosis"
                    />

                <FrameLayout
                    android:id="@+id/auto_list_container2"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:visibility="gone"
                    android:background="@color/colorPrimaryDark"/>

            </LinearLayout>


            </RelativeLayout>
        </NestedScrollView>

    </RelativeLayout>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-03 03:08:06

通过创建以下内容解决了此问题:

代码语言:javascript
复制
public class NoInterceptScrollView extends ScrollView {

    public NoInterceptScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return false;
    }

}

并将其用作父类..and将两个嵌套的scrollview更改为scrollview+我删除了禁用父触摸的代码……

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52139495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档