为什么ViewPager不会在RelativeLayout中滑动?

问题描述 投票:0回答:3

将“线性布局”更改为“相对”布局后,滑动更改不起作用。

整个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>

有什么问题?

它也不适用于Frame Layout。

有什么建议吗?

java android android-layout kotlin android-viewpager
3个回答
4
投票

NestedScrollView现在高于(z轴)ViewPager,所以ViewPager没有接收到触摸事件。加

android:layout_below="@+id/singleSlider"

到你的NestedScrollView


0
投票

我认为您的View-pager和NestedScrollView在使用Linear Layout之前会重叠。所以它逐一进行,但现在在相对布局中它是重叠的。使用layout_below属性


0
投票

现在你的嵌套滚动视图和你的视图寻呼机只是2个单独的东西,彼此不能确定你是否想要你的嵌套滚动视图中的视图寻呼机,或者如果你想在你的视图寻呼机内嵌套滚动所以我将显示视图嵌套滚动内部

<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>

然后当你调用你的滚动视图

你也可以设置

android:fillViewport="true"

在嵌套滚动视图上定义scrollview是否应拉伸其内容以填充视口

如果这不是你想要的,你可以展示模拟或显示你想要它如何运作的东西,我会相应地编辑我的答案

© www.soinside.com 2019 - 2024. All rights reserved.