2016-05-20 13 views
8

स्क्रॉल नहीं कर रहा है मेरे पास एक नेस्टेड स्क्रॉल व्यू है जिसमें एक रैखिक लेआउट के अंदर सामग्री शामिल है।एंड्रॉइड नेस्टेड स्क्रॉलव्यू

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:CoverFlowPager="http://schemas.android.com/apk/res-auto" 
    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.v4.widget.NestedScrollView 
     android:id="@+id/scroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="10dp" 
     android:clipToPadding="false" 
     android:fillViewport="true" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
     </LinearLayout> 

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

</FrameLayout> 

मेरे पास यह लेआउट व्यूपेजर के अंदर है और व्यूपेजर कॉर्डिनेटरआउट के अंदर है।

<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:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

अब जब मैं दृश्य को स्क्रॉल करता हूं तो दृश्य स्क्रॉल नहीं होता है। लेकिन चूंकि कॉर्डिनेटर लेआउट के अंदर लेआउट रखा जाता है जब तक टूलबार छुपा नहीं जाता है। लेकिन यह स्क्रॉल नहीं कर रहा है।

यहां मेरी मुख्य गतिविधि xml है, व्यू पेजर एक टैबड लेआउट के अंदर है।

<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:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

      <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       xmlns:attrs="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="?attr/colorPrimary" 
       app:layout_scrollFlags="scroll|enterAlways" 
       app:popupTheme="@style/AppTheme.PopupOverlay"> 

      <FrameLayout 
       android:id="@+id/titleContainer" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center"  
       android:gravity="center"> 

       <com.CustomFontTextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:text="Toolbar Title" 
        android:textColor="#ffffff" 
        attrs:customFont="handyman_bold" 
        android:textSize="8pt" 
        android:layout_marginLeft="-20dp" 
        android:id="@+id/toolbar_title"/> 
      </FrameLayout> 

      <ImageButton 
       android:id="@+id/btn_ToolBarRightBtn" 
       android:layout_width="32dp" 
       android:layout_height="28dp" 
       android:tag="0" 
       android:background="@null" 
       android:scaleType="fitXY" 
       android:src="@drawable/icon_shopping" 
       android:layout_alignParentRight="true" 
       android:layout_gravity="right" 
       android:layout_marginRight="10dp" 
       /> 

     </android.support.v7.widget.Toolbar> 

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

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

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_gravity="bottom" 
     android:background="@color/offwhite" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

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

यहाँ मेरी स्क्रीनशॉट है,

प्रारंभिक दृश्य enter image description here

जब दृश्य स्क्रॉल किया जाता है, यह स्क्रॉल केवल शीर्ष नेविगेशन पट्टी को छिपाने के लिए। इसके टैब पट्टी के नीचे आइटम प्रदर्शित करने के लिए स्क्रॉल नहीं,

enter image description here

+0

'एंड्रॉयड नहीं करना चाहिए: layout_height =" match_parent "' NestedScrool देखें में हो 'एंड्रॉयड: layout_height =" wrap_content "' ... और अपने घोंसलेदार रैखिक लेआउट में भी? – longilong

+0

क्या आप जो हासिल करने की कोशिश कर रहे हैं उसका एक दृश्य जोड़ सकते हैं? – jobbert

+0

कृपया स्क्रीनशॉट देखें – Zach

उत्तर

1

app:layout_behavior="..." CoordinatorLayout का एक सीधा बच्चे पर स्थापित किया जाना चाहिए। यदि आपका ViewPager CoordinatorLayout का प्रत्यक्ष बच्चा है, तो इसे ViewPager घोषणा पर रखें। यहाँ से

0

उद्धरण: outlined here रूप ViewPager पर layout_behavior संपत्ति तो: Troubleshooting Coordinator Layouts

जब एक ViewPager और एक माता पिता गतिविधि में मदों की एक सूची के साथ एक टुकड़ा के बीच समन्वय, आप अनुप्रयोग रखना चाहते हैं पेजर के भीतर स्क्रॉल को बुलबुला किया जाता है और कोऑर्डिनेटरलायआउट द्वारा प्रबंधित किया जा सकता है। ध्यान दें कि आपको उस ऐप को नहीं रखना चाहिए: layout_behavior प्रॉपर्टी कहीं भी खंड या भीतर की सूची के भीतर।

0

आप इसे आजमा सकते हैं! मुझे अपने ऐप के साथ एक ही समस्या थी। यह मेरे लिए काम किया।

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 


    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:attrs="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways" 
     app:popupTheme="@style/AppTheme.PopupOverlay"> 

     <FrameLayout 
      android:id="@+id/titleContainer" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 

      android:gravity="center"> 

      <com.CustomFontTextView 
       android:id="@+id/toolbar_title" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="-20dp" 
       android:gravity="center" 
       android:text="Toolbar Title" 
       android:textColor="#ffffff" 
       android:textSize="8pt" 
       attrs:customFont="handyman_bold" /> 
     </FrameLayout> 

     <ImageButton 
      android:id="@+id/btn_ToolBarRightBtn" 
      android:layout_width="32dp" 
      android:layout_height="28dp" 
      android:layout_alignParentRight="true" 
      android:layout_gravity="right" 
      android:layout_marginRight="10dp" 
      android:background="@null" 
      android:scaleType="fitXY" 
      android:src="@drawable/icon_shopping" 
      android:tag="0" /> 


    </android.support.v7.widget.Toolbar> 

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:background="@color/offwhite" /> 


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


</LinearLayout> 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/scroll" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="10dp" 
    android:clipToPadding="false" 
    android:fillViewport="true"> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"></LinearLayout> 
</android.support.v4.widget.NestedScrollView> 

0

तो यहाँ समस्या है, तो आप FrameLayout के भीतर एक NestedScrollView नहीं हो सकता।

इसके अलावा, इसे बनाने के लिए एक्सएमएल में कुछ अन्य छोटे बदलावों की आवश्यकता है। टैबलाउट की तरह ऐपबार लेआउट के अंदर होना चाहिए और पिन किया जाना चाहिए।

अपने कोड है ->

</android.support.v7.widget.Toolbar> 

<android.support.design.widget.TabLayout 
android:id="@+id/tabs" 
android:layout_gravity="bottom" 
android:background="@color/offwhite" 
android:layout_width="match_parent" 
app:layout_collapseMode="pin" 
app:layout_anchor="@+id/appbar" 
app:layout_anchorGravity="bottom" 
android:layout_height="wrap_content"/> 

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


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

और -> फ्रेम लेआउट दूर करने के लिए अपने टुकड़ा कोड बदलें!

<android.support.v4.widget.NestedScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:CoverFlowPager="http://schemas.android.com/apk/res-auto" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/scroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="10dp" 
     android:clipToPadding="false" 
     android:fillViewport="true"> 

     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
     </LinearLayout> 

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

आशा है कि इससे मदद मिलती है!

+0

@Zach मैंने अपडेट किया गया जवाब कृपया जांचें। –

0

इस

scroll.setOnTouchListener(new View.OnTouchListener() { 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     v.getParent().requestDisallowInterceptTouchEvent(true); 
     return false; 
    } 
}); 
0

ScrollingViewBehavior कोशिश सिर्फ ऊपर और नीचे अपने ViewPager को ऑफसेट जोड़ने है। आम तौर पर ऑफसेट ऐपबारलाइट ऊंचाई पर निर्भर करता है और यह आपके टैबलाइट ऊंचाई पर निर्भर नहीं करता है क्योंकि यह ऐपबारलाउट में नहीं है। तो, जल्दी वैकल्पिक हल के लिए आप सिर्फ paddingBottom अपने ViewPager को इस तरह जोड़ सकते हैं:

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

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_gravity="bottom" 
     android:background="@android:color/black" 
     android:layout_width="match_parent" 
     android:layout_height="50dp"/> 
संबंधित मुद्दे