简体   繁体   English

为什么ViewPager不在RelativeLayout内滑动?

[英]Why ViewPager doesn't swiping inside RelativeLayout?

After changing Linear Layout to Relative layout swipe change doesn't work. 将“线性布局”更改为“相对布局”后,滑动更改不起作用。

Whole xml code here. 整个xml代码在这里。

<RelativeLayout 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.v4.view.ViewPager
        android:id="@+id/singleSlider"
        android:layout_width="match_parent"
        android:layout_height="@dimen/slider_height"
        android:background="@color/colorPrimaryDark" />

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/singleScroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        ...

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

</RelativeLayout>

What can be a problem? 有什么问题吗?

It doesn't work also with Frame Layout. 它也不适用于“帧布局”。

Any suggestion? 有什么建议吗?

The NestedScrollView is now above (z-axis) the ViewPager , so the ViewPager doesn't receive the touch events. 所述NestedScrollView是现在上述(z轴)的ViewPager ,所以ViewPager不接收触摸事件。 Add

android:layout_below="@+id/singleSlider"

to your NestedScrollView . 到您的NestedScrollView

I think your View-pager and NestedScrollView are overlapping earlier you are using Linear Layout . 我认为您在使用线性布局之前,您的View-pager和NestedScrollView是重叠的 So it goes one by one but now in Relative Layout it is overlapping. 因此它一一进行,但是现在在相对布局中它是重叠的。 Use layout_below attribute 使用layout_below属性

right now your nested scroll view and your view pager are just 2 seperate things that over lap each other not sure if you want your view pager inside your nested scroll view or if you want the nested scroll inside of your view pager so i will show view inside the nested scroll 现在,您的嵌套滚动视图和视图分页器只是两个相互重叠的独立事物,不确定是否要在嵌套滚动视图中使用视图分页器,还是要在视图分页器中嵌套嵌套滚动条,以便我显示视图在嵌套滚动内

<RelativeLayout 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.v4.widget.NestedScrollView
        android:id="@+id/singleScroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.view.ViewPager
        android:id="@+id/singleSlider"
        android:layout_width="match_parent"
        android:layout_height="@dimen/slider_height"
        android:background="@color/colorPrimaryDark" />

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

</RelativeLayout>

then when you call your scrollview 然后当您调用滚动视图时

you can also set 你也可以设置

android:fillViewport="true"

on the nested scroll view to Defines whether the scrollview should stretch its content to fill the viewport 在嵌套滚动视图上,定义滚动视图是否应拉伸其内容以填充视口

if this is not what you wanted could you maybe show a mock up or something showing how you want it to function and I will edit my answer accordingly 如果这不是您想要的,可以显示一个模型或显示您希望它如何运行的内容,我将相应地编辑我的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM