<bdo id='j92BV'></bdo><ul id='j92BV'></ul>
      <i id='j92BV'><tr id='j92BV'><dt id='j92BV'><q id='j92BV'><span id='j92BV'><b id='j92BV'><form id='j92BV'><ins id='j92BV'></ins><ul id='j92BV'></ul><sub id='j92BV'></sub></form><legend id='j92BV'></legend><bdo id='j92BV'><pre id='j92BV'><center id='j92BV'></center></pre></bdo></b><th id='j92BV'></th></span></q></dt></tr></i><div id='j92BV'><tfoot id='j92BV'></tfoot><dl id='j92BV'><fieldset id='j92BV'></fieldset></dl></div>

      <small id='j92BV'></small><noframes id='j92BV'>

    1. <legend id='j92BV'><style id='j92BV'><dir id='j92BV'><q id='j92BV'></q></dir></style></legend>

        <tfoot id='j92BV'></tfoot>
      1. 如何在 NestedScrollView 中使用 RecyclerView 制作 ViewPager

        How can I make work ViewPager with RecyclerView inside NestedScrollView(如何在 NestedScrollView 中使用 RecyclerView 制作 ViewPager)

      2. <small id='YC37p'></small><noframes id='YC37p'>

          <bdo id='YC37p'></bdo><ul id='YC37p'></ul>
            <tbody id='YC37p'></tbody>

            <tfoot id='YC37p'></tfoot>

            1. <i id='YC37p'><tr id='YC37p'><dt id='YC37p'><q id='YC37p'><span id='YC37p'><b id='YC37p'><form id='YC37p'><ins id='YC37p'></ins><ul id='YC37p'></ul><sub id='YC37p'></sub></form><legend id='YC37p'></legend><bdo id='YC37p'><pre id='YC37p'><center id='YC37p'></center></pre></bdo></b><th id='YC37p'></th></span></q></dt></tr></i><div id='YC37p'><tfoot id='YC37p'></tfoot><dl id='YC37p'><fieldset id='YC37p'></fieldset></dl></div>
                • <legend id='YC37p'><style id='YC37p'><dir id='YC37p'><q id='YC37p'></q></dir></style></legend>
                  本文介绍了如何在 NestedScrollView 中使用 RecyclerView 制作 ViewPager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用带有 ViewPager 的 NestedScrollView.NestedScrollView 内部有一个 LinearLayout,最后有一些 TextView、TabLayout 和 ViewPager.TextViews 占据了大部分空间,而为 ViewPager 留下了一点空间.ViewPager 使用两个 Fragment,其中一个有几个 TextViews 和 ImageViews,另一个 Fragment 有一个 RecyclerView.

                  I am using NestedScrollView with ViewPager. NestedScrollView has a LinearLayout inside with some TextViews, TabLayout and ViewPager at the end. TextViews occupy most of the space and for ViewPager left a little space. ViewPager using two fragments, in one of them there is a few TextViews and ImageViews and in another fragment there is a RecyclerView.

                  当我将 ViewPager 的高度设置为 WRAP_CONTENT 时,它只占用剩下的空间,我无法滚动查看第一个片段的其余部分,而第二个片段在小 ViewPager 内滑动.

                  When I set ViewPager's height to WRAP_CONTENT it takes only space that left and I can't scroll to see the rest of the first fragment, and the second fragment scoll inside little ViewPager.

                  例如,当我将 ViewPager 的高度设置为 1000dp 时,我可以在第一个片段上向下滚动,但第二个片段仍在小 ViewPager 内滚动.在我使用 RecyclerView scoll 在第一个 Fragment 中滚动片段后不再工作.

                  When I set ViewPager's height to 1000dp for example, I am able to scroll down on first fragment, but the second fragment still scrolling inside little ViewPager. And after I scroll in fragment with RecyclerView scoll in the first Fragment not working anymore.

                  如何解决滚动问题并使 ViewPager 与 WRAP_CONTENT 一起工作?

                  How can I fix scrolling problem and make ViewPager work with WRAP_CONTENT?

                  这是我的代码:

                  <?xml version="1.0" encoding="utf-8"?>
                  <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      xmlns:app="http://schemas.android.com/apk/res-auto"
                      xmlns:tools="http://schemas.android.com/tools"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent">
                  
                      <android.support.design.widget.AppBarLayout
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content">
                  
                          <android.support.v7.widget.Toolbar
                              android:id="@+id/toolbar"
                              android:layout_width="match_parent"
                              android:layout_height="?attr/actionBarSize"
                              android:background="?attr/colorPrimary" />
                  
                      </android.support.design.widget.AppBarLayout>
                  
                      <android.support.v4.widget.NestedScrollView
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          app:layout_behavior="@string/appbar_scrolling_view_behavior"
                          app:layout_scrollFlags="scroll"
                          android:fillViewport="true">
                  
                          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                              android:layout_width="match_parent"
                              android:layout_height="match_parent"
                              android:background="@color/mainBackground"
                              android:orientation="vertical">
                  
                              <TextView
                                  android:layout_width="wrap_content"
                                  android:layout_height="wrap_content"
                                  android:text="SOME TEXT" />
                  
                              <TextView
                                  android:layout_width="wrap_content"
                                  android:layout_height="wrap_content"
                                  android:text="SOME TEXT" />
                  
                              <TextView
                                  android:layout_width="wrap_content"
                                  android:layout_height="wrap_content"
                                  android:text="SOME TEXT" />
                  
                              <android.support.design.widget.TabLayout
                                  android:id="@+id/tabLayout"
                                  android:layout_width="match_parent"
                                  android:layout_height="wrap_content" />
                  
                              <android.support.v4.view.ViewPager
                                  android:id="@+id/viewPager"
                                  android:layout_width="match_parent"
                                  android:layout_height="wrap_content" />
                  
                          </LinearLayout>
                  
                      </android.support.v4.widget.NestedScrollView>
                  
                  </android.support.design.widget.CoordinatorLayout>
                  

                  推荐答案

                  我认为你应该像这样覆盖 ViewPager:

                  I think you should override ViewPager like this:

                  @Override
                  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                  
                      int height = 0;
                      for (int i = 0; i < getChildCount(); i++) {
                          View child = getChildAt(i);
                          child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
                          int h = child.getMeasuredHeight();
                          if (h > height) height = h;
                      }
                      heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
                      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                  }
                  

                  这篇关于如何在 NestedScrollView 中使用 RecyclerView 制作 ViewPager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
                  cocos2d-android: how to display score(cocos2d-android:如何显示分数)
                  Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                  SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                  Android file copy(安卓文件拷贝)
                  Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)
                  <legend id='GFx51'><style id='GFx51'><dir id='GFx51'><q id='GFx51'></q></dir></style></legend>
                  <i id='GFx51'><tr id='GFx51'><dt id='GFx51'><q id='GFx51'><span id='GFx51'><b id='GFx51'><form id='GFx51'><ins id='GFx51'></ins><ul id='GFx51'></ul><sub id='GFx51'></sub></form><legend id='GFx51'></legend><bdo id='GFx51'><pre id='GFx51'><center id='GFx51'></center></pre></bdo></b><th id='GFx51'></th></span></q></dt></tr></i><div id='GFx51'><tfoot id='GFx51'></tfoot><dl id='GFx51'><fieldset id='GFx51'></fieldset></dl></div>

                  <small id='GFx51'></small><noframes id='GFx51'>

                      <tfoot id='GFx51'></tfoot>
                            <tbody id='GFx51'></tbody>

                          • <bdo id='GFx51'></bdo><ul id='GFx51'></ul>