2016-05-13 8 views
6

मैं एक टुकड़ा के साथ NonSwipeableViewPager लागू इस तरह NestedScrollView है, क्या मैं उम्मीद है कि scrollview ऊपर स्क्रॉल और 2 textviews दिखा सकते हैं:NestedScrollView match_parent ऊंचाई बच्चे के साथ स्क्रॉल नहीं कर सकता

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

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

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

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

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="16dp" 
       android:src="@drawable/ic_up" /> 

     </RelativeLayout> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Text 1" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Text 2" /> 

    </LinearLayout> 

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

लेकिन यह स्क्रॉल नहीं कर सकता है, मैं कई मायनों कोशिश की, लेकिन अभी तक किसी भी समाधान

+1

scrollview की जरूरत है अपने बच्चे की ऊंचाई –

+0

@TimCastelijns wrap_content जा करने के लिए तो हम किसी भी तरीके match_parent ऊंचाई के साथ यह करने के लिए नहीं है, हम करते हैं? –

+0

यह है कि स्क्रॉलव्यू कैसे काम करता है, आप स्क्रॉलव्यू को माता-पिता से मेल खाने के लिए सेट कर सकते हैं, लेकिन स्क्रॉलव्यू के बच्चे को नहीं, जिसे सामग्री लपेटने की आवश्यकता है –

उत्तर

27
<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

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

यह LinearLayout android:layout_height="wrap_content" होना चाहिए नहीं मिला।

उस के लिए कारण यह है कि अगर scrollview के बच्चे scrollview ही (ऊंचाई के लिए दोनों match_parent) इसका मतलब है के माध्यम से स्क्रॉल करने के लिए कुछ भी नहीं है कि वहाँ है, क्योंकि वे एक ही आकार के होते हैं और scrollview के रूप में ही किया जाएगा के रूप में एक ही आकार है स्क्रीन के रूप में उच्च।

यदि लाइनरलेआउट की ऊंचाई wrap_content है तो ऊंचाई स्क्रीन की ऊंचाई से संबंधित नहीं है और स्क्रॉलव्यू इसके माध्यम से स्क्रॉल करने में सक्षम होगा।

बस याद रखें कि एक scrollview केवल 1 प्रत्यक्ष बच्चे हो सकता है, और उस बच्चे android:layout_height="wrap_content"

+0

बहुत बढ़िया आदमी! ......... –

+1

मेरे लिए, केवल ' fillViewPort = true' woked। मेरे मामले में बच्चे की ऊंचाई कोई फर्क नहीं पड़ता –

+0

fillViewPort = true ने इसे मेरे लिए भी हल किया। धन्यवाद! –

-4

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
+1

क्या आप अपना उत्तर अधिक समझा सकते हैं? – Caipivara

1

की जरूरत है मेरे मामले app:layout_behavior="@string/appbar_scrolling_view_behavior" में यह केवल काम कर रहा है, तो कुछ एक चेहरा समस्या यह कोशिश हो जाएगा और आपकी समस्या भी हल हो सकती है। आपको android:fillViewport="true" भी जोड़ना चाहिए, लेकिन इसके बिना मेरा कोड काम कर रहा है।

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="@drawable/subscription_background" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
संबंधित मुद्दे