Java 为什么ViewPager没有';t在相对论中滑动?
将线性布局更改为相对布局后,滑动更改不起作用。 这里有完整的xml代码Java 为什么ViewPager没有';t在相对论中滑动?,java,android,android-layout,kotlin,android-viewpager,Java,Android,Android Layout,Kotlin,Android Viewpager,将线性布局更改为相对布局后,滑动更改不起作用。 这里有完整的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"
<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>
...
什么是问题
它不适用于框架布局
有什么建议吗?嵌套的滚动视图现在位于
查看页面
上方(z轴),因此查看页面
不会接收触摸事件。
加
到您的
嵌套滚动视图
NestedScrollView现在位于ViewPager
上方(z轴),因此ViewPager
不会接收触摸事件。
加
到您的
嵌套滚动视图
我认为您的视图寻呼机和NestedScrollView在您之前使用的线性布局中是重叠的。所以它一个接一个地走,但现在在相对布局中它是重叠的。
使用下面的layout\u属性我认为您的视图寻呼机和嵌套滚动视图在前面使用线性布局时重叠。所以它一个接一个地走,但现在在相对布局中它是重叠的。
使用下面的布局\u属性现在您的嵌套滚动视图和视图分页器只是两个相互重叠的独立对象,不确定您是希望视图分页器位于嵌套滚动视图内,还是希望视图分页器位于嵌套滚动视图内,因此我将在嵌套滚动视图内显示视图
<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>
在嵌套滚动视图上,定义滚动视图是否应拉伸其内容以填充视口
如果这不是你想要的,你可以展示一个模型或者一些你想要它如何工作的东西,我会相应地编辑我的答案,现在你的嵌套滚动视图和你的视图页面只是两个相互重叠的独立的东西,不确定你是想把视图页面放在嵌套滚动视图中还是你想要嵌套的滚动条位于视图寻呼机内,因此我将显示嵌套滚动条内的视图
<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>
在嵌套滚动视图上,定义滚动视图是否应拉伸其内容以填充视口
如果这不是您想要的,您是否可以显示一个模型或一些显示您希望它如何工作的东西,我将相应地编辑我的答案是的,现在滑动工作,但NestedScrollView中的内容变为不工作visible@TigranBabajanyan如果ViewPager现在可见(您可以通过为其提供背景色进行检查),那么这应该是另一个问题,可能是数据或适配器的问题。我建议您为此发布一个新问题,并附上相关代码。是的,现在滑动可以正常工作,但NestedScrollView中的内容却无法正常工作visible@TigranBabajanyan如果ViewPager现在可见(您可以通过给它一个背景色进行检查),那么这应该是另一个问题,可能是数据或适配器的问题。我建议你用相关代码发布一个新问题。是的,它可以工作,但NesteedScrollView中的内容变得不可见,你知道吗?我认为你的视图页面比嵌套的滚动视图占用了更多的空间。你可以做一件事,将整个高度空间分成两个相等的部分,给嵌套和视图页面赋予相等的高度。是的,它可以工作,但嵌套的滚动视图中的内容变得不可见,你知道吗?我认为你的视图页面比嵌套滚动视图占用了更多的空间。你可以做一件事,把整个高度空间分成两个相等的部分,给嵌套和视图页面赋予相等的高度。我不想把视图页面放在滚动视图中,因为我不想在滚动视图中滚动它,我不想把它和其他元素放在一起ScrollView中的viewpager,因为我不想在scroll view中与其他元素一起滚动它
android:fillViewport="true"