【问题标题】:I am not able to use viewpager inside scroll-view and tab layout without toolbar layout?我无法在没有工具栏布局的情况下在滚动视图和选项卡布局中使用 viewpager?
【发布时间】:2017-10-23 13:17:21
【问题描述】:

我想用

<android.support.v4.widget.NestedScrollView
            android:id="@+id/scroll_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/action_bar"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

                <RelativeLayout
                    android:id="@+id/main_content"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    tools:visibility="gone">

                    <RelativeLayout
                        android:id="@+id/image"
                        android:layout_width="match_parent"
                        android:layout_height="220dp">

                        <ImageView
                            android:id="@+id/cover_image"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:scaleType="centerCrop"/>

                    </RelativeLayout>

                    <RelativeLayout
                        android:id="@+id/tab_layout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/image"
                        android:background="@color/card_background">

                        <android.support.design.widget.TabLayout
                            android:id="@+id/topTabs"
                            style="@style/TextAppearance.Tab"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            app:tabBackground="@color/bpWhite"
                            app:tabGravity="fill"
                            app:tabMode="fixed"
                            app:tabTextColor="@color/secondary_text_color"
                            custom:tabIndicatorColor="@color/secondary_text_color"
                            custom:tabIndicatorHeight="2dp" />

                        <View
                            android:layout_width="match_parent"
                            android:layout_height="2dp"
                            android:layout_below="@id/topTabs"
                            android:background="@drawable/tab_layout_drop_shadow" />
                    </RelativeLayout>

                    <android.support.v4.view.ViewPager
                        android:id="@+id/viewPager"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_below="@id/tab_layout" />

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

无法滚动,view-pager 或 tab-layout 无法滚动我尝试了所有方法。

1.在view-pager中禁用touch事件,为scroll-view启用touch事件。

2.尝试了其他滚动视图,如 Nestedscrollview、Parallaxscrollview、协调器布局。如果我使用协调器布局,则无法更改工具栏。

  1. 我对所有滚动视图都使用了 fillviewport true。但它仍然无法滚动。

解决问题的任何其他方法。

【问题讨论】:

  • 你能在你尝试过的地方添加你的完整xml吗
  • 我无法读取您的 XML。顶部的杂物是什么?
  • @KalaBalik 你现在可以检查一下吗

标签: android android-viewpager scrollview android-nestedscrollview


【解决方案1】:

您可以使用不带工具栏的视图分页器,但不能使用不带工具栏的选项卡。

【讨论】:

  • 你能告诉我如何使用没有工具栏的协调器布局
  • 你到底想用它做什么?
  • 如果你使用的是最新的android studio,coordinator layout一般会在新建项目时添加。
【解决方案2】:

虽然目前还不清楚,但你在这里想要实现什么,布局没有问题,真的。

如果您设置了设计支持库correctly

如果您尝试禁用某些触摸事件并没有弄乱您的听众,并且

如果您取出tools:visibility="gone" 属性(以便显示任何可以滚动的内容)并且

如果您决定ViewPager 的特定高度(或wrap_content)和

如果您取出第一个不必要的RelativeLayouts(可选),

那么你应该可以滚动了。至少我在 Android Studio 的布局编辑器中。

【讨论】:

  • 我不想给他的viewpager固定高度,在侧面viewpager中我有2个片段,一个带有recyclerview,一个带有正常的Liner布局,我也没有使用任何触摸事件。还是这样无法滚动
  • 抱歉,我无法重现该问题。
猜你喜欢
  • 2017-08-22
  • 2017-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-11
  • 1970-01-01
  • 2017-10-26
相关资源
最近更新 更多