2017-02-21 2 views
0

Я создал просмотрщик с 3 фрагментами в Coordinatorlayout.
Внутри каждого Viewpager вы можете найти NestedScrollView с некоторым контентом.
Но если я прокручиваю содержимое вверх и вниз по его запаздыванию.
Я протестировал и заменил NestedScrollView обычным ScrollView, и он был гладким. Проблема заключается в том, что с помощью nestedscrollview.
Надеюсь на помощь. Благодарю.Android NestedScrollView отстает при прокрутке вверх и вниз

<android.support.design.widget.CoordinatorLayout 
    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.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" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay"/> 

     <android.support.design.widget.TabLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/tab_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top" 
      app:tabGravity="fill" 
      app:tabIndicatorColor="@color/black" 
      app:tabIndicatorHeight="1dp" 
      app:tabMaxWidth="0dp" 
      app:tabMode="fixed" 
      app:tabSelectedTextColor="@color/white" 
     app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget" 
      app:tabTextColor="@color/black"/> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/view_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

    <include 
     android:id="@+id/floating_action_button" 
     layout="@layout/floating_action_button_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</android.support.design.widget.CoordinatorLayout> 

Внутри ViewPager вы можете найти:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView 
    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:id="@+id/fragment_first" 
    style="@style/NestedScrollBarStyle" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    app:layout_scrollFlags="scroll|enterAlways" 
    tools:context="com.amirkhan.template1.MainActivity"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="16dp"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:text="111111111111111111111111111"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:text="111111111111111111111111111"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:text="111111111111111111111111111"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:text="111111111111111111111111111"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:text="111111111111111111111111111"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="sadsff"/> 
    </LinearLayout> 

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

after adding android:nestedScrollingEnabled="false"

ответ

1

H Amir,

пожалуйста, поставить строку ниже в код

recyclerView.setNestedScrollingEnabled(false); 
+0

нет рециркуляции. –

+0

Извините, в случае использования в режиме рециркуляции используйте свой макет –

0

Используйте эту с ваш объект LinearLaout в вашем Java-коде:

linearLayout.setNestedScrollingEnabled (false);

0

Используйте этот код

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v4.widget.NestedScrollView 
     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:id="@+id/fragment_first" 
     style="@style/NestedScrollBarStyle" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     app:layout_scrollFlags="scroll|enterAlways" 
     android:nestedScrollingEnabled="false" 
     tools:context="com.amirkhan.template1.MainActivity"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="16dp"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:text="111111111111111111111111111"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:text="111111111111111111111111111"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:text="111111111111111111111111111"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:text="111111111111111111111111111"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:text="111111111111111111111111111"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="sadsff"/> 
     </LinearLayout> 

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

Я получаю следующее: Следующие классы не могут быть созданы: - android.support.v4.widget.NestedScrollView –

+0

все еще то же сообщение –

+0

Невозможно получить ошибку. Мы просто добавляем свойство просмотра прокрутки в xml правильно? Пожалуйста, убедитесь, что он работал до редактирования, о котором я упоминаю. – EKN

0

Это один я сделал и работает отлично.

Та часть, которая у в основном нужно:

<android.support.v4.widget.NestedScrollView 
android:id="@+id/bottom_sheet" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:clipToPadding="true" 
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 

И я сделал это один для вас, так что вы можете попробовать его.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 
<android.support.v4.widget.NestedScrollView 
    android:id="@+id/bottom_sheet" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:clipToPadding="true" 
     app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 
<LinearLayout> 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:padding="16dp"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:text="111111111111111111111111111"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:text="111111111111111111111111111"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:text="111111111111111111111111111"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:text="111111111111111111111111111"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:text="111111111111111111111111111"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="sadsff"/> 
</LinearLayout> 
</android.support.v4.widget.NestedScrollView> 

</android.support.design.widget.CoordinatorLayout> 
Смежные вопросы