5

मेरे पास नए CollapsingToolbarLayout को लागू करने का प्रयास करने में कुछ समस्याएं हैं। स्क्रॉलिंग, विस्तार और ढहने ठीक काम करते हैं, लेकिन मेरे ImageView (कोई फर्क नहीं पड़ता कि मैं किस प्रकार का संसाधन सेट करता हूं) विस्तारित टूलबार की पूरी ऊंचाई को कवर नहीं करता है। यहाँ देखें:ImageView CollapsingToolbarLayout में पूर्ण ऊंचाई को कवर नहीं किया गया है?

expanded collapsed

यहाँ मैं छवि को देखने पर android:src="@color/red" निर्धारित करते हैं, लेकिन यह कभी वास्तविक उपकरण पट्टी को शामिल किया गया। यह बिटमैप्स के साथ भी काम नहीं करता है। मैं नीचे अपना लेआउट पोस्ट कर रहा हूं।

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <!-- content --> 
    <android.support.design.widget.CoordinatorLayout 
     android:fitsSystemWindows="true" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <android.support.design.widget.AppBarLayout 
      android:layout_height="@dimen/appbar_expanded_height" 
      android:layout_width="match_parent" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      android:fitsSystemWindows="true"> 
      <android.support.design.widget.CollapsingToolbarLayout 
       android:layout_height="match_parent" 
       android:layout_width="match_parent" 
       app:layout_scrollFlags="scroll|exitUntilCollapsed" 
       app:expandedTitleMarginStart="48dp" 
       app:expandedTitleMarginEnd="64dp" 
       app:contentScrim="?attr/colorPrimary" 
       android:fitsSystemWindows="true"> 

       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:fitsSystemWindows="true" 
        android:src="@color/red_600" 
        android:scaleType="centerCrop" 
        app:layout_collapseMode="parallax" 
        /> 
       <android.support.v7.widget.Toolbar 
        android:id="@+id/toolbar" 
        app:layout_collapseMode="pin" 
        android:layout_width="match_parent" 
        android:layout_height="?attr/actionBarSize"> 
       </android.support.v7.widget.Toolbar> 

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

     <!-- I load fragments here --> 
     <FrameLayout 
      android:id="@+id/fragment_content" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 
    </android.support.design.widget.CoordinatorLayout> 

    <!-- nav drawer --> 
    <fragment 
     android:layout_width="@dimen/drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start"/> 
</android.support.v4.widget.DrawerLayout> 

मुझे लगता है, के साथ फर्क सिर्फ इतना है उदाहरण के लिए, पनीर-क्रिस बेंस-ऐप, कि मैं एक FrameLayout को app:layout_behavior रहा हूं है। हालांकि, उस फ्रेम के अंदर मैं उन खंडों को लोड करता हूं जिनमें रूट दृश्य के रूप में NestedScrollView है, और ऐसा लगता है कि यह ठीक काम करता है।

उत्तर

4

मुझे पता चला कि ब्लू स्ट्रिप टूलबार पृष्ठभूमि थी। अर्थात्, मैं था:

<item name="toolbarStyle">@style/MyToolbarStyle</item> 

मेरे विषय में, और:

<style name="MyToolbarStyle"> 
    <item name="android:background">?attr/colorPrimary</item> 
</style> 

मैं colorPrimary साथ टिंट टूलबार को यह किया करते थे। हालांकि यदि आप डिज़ाइन लाइब्रेरी में जाना चाहते हैं, तो आपको से छुटकारा पाना चाहिए: ध्वस्त टूलबार रंग पहले ही विशेषता CollapsingToolbarLayout पर प्रबंधित किया गया है।

+0

मैं ठीक उसी मुद्दा जहां मेरी छवि दृश्य हमेशा टूलबार नीचे है। मुझे यकीन नहीं है कि मैं समझता हूं कि आपने इसे कैसे ठीक किया है। – alextk

+0

मैंने शैलियों और लेआउट फ़ाइल में, दोनों टूलबार के एंड्रॉइड: पृष्ठभूमि विशेषता को हटा दिया। – natario

4

मुझे एक ही समस्या थी, ढहने वाली टूलबार में छवि की पूरी ऊंचाई शामिल नहीं थी, लेकिन AppBarLayout से एकल लाइन को हटाने के साथ तय किया गया। आपको बस android:fitsSystemWindows="true को हटाने की आवश्यकता है और आप कर चुके हैं।

<android.support.design.widget.AppBarLayout 
     android:layout_height="@dimen/appbar_expanded_height" 
     android:layout_width="match_parent" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     android:fitsSystemWindows="true"> 

अंतिम पंक्ति को हटाएं, जैसा कि है।

android:fitsSystemWindows="true" 

, यह है कि आगे बढ़ने के लिए ...

संबंधित मुद्दे