2015-09-18 20 views
9

मुझे अपने फ्रेमलेआउट (ड्रॉवर लेआउट में कंटेनर) में कोई समस्या है। फ्रेमलेआउट की ऊंचाई स्क्रीन की ऊंचाई से अधिक है (नीचे एंड्रॉइड डिफ़ॉल्ट मेनू बटन के नीचे)।एंड्रॉइड - फ़्रेम लेआउट ऊंचाई समन्वयक लेआउट से मेल नहीं खाती

<android.support.design.widget.CoordinatorLayout 
     android:id="@+id/main_content" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/navContainer" 
      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="wrap_content" 
       android:minHeight="?attr/actionBarSize" 
       app:layout_scrollFlags="scroll|enterAlways" /> 

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

     <FrameLayout 
      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.CoordinatorLayout> 

Height exceeding as seen in Android Studio Designer

+1

मैं एक ही समस्या हो रही है, इस एंड्रॉयड समन्वयक बग है या इस के लिए अपने किसी भी समाधान नहीं है: यहाँ AppBarLayout के लिए कस्टम व्यवहार वर्ग है। (एक्शन बार ऊंचाई की कमी के रूप में मार्जिन नीचे देने के बिना) – DeepakPanwar

उत्तर

4

मेरा पहला प्रयास FrameLayout पर एक android:layout_marginBottom="?attr/actionBarSize" स्थापित करने के लिए किया गया था। इसने गैर-स्क्रोल करने योग्य विचारों के समाधान को हल किया, जिसमें कोई लंबवत स्क्रॉल करने योग्य सामग्री (match_parent ऊंचाई के साथ सामान्य सापेक्ष लयआउट) के मामले में "निश्चित" ऊंचाई होती है। पैरेंट तल (android:layout_alignParentBottom="true") में एक घटक को संरेखित करना अभी भी एक दृश्यमान तत्व में परिणाम देता है। एंड्रॉइड स्टूडियो के पूर्वावलोकनकर्ता में ऊंचाई की कोई सीमा दिखाई नहीं दे रही है।

हालांकि, यह मार्जिनबटन-फिक्स उन टुकड़ों के लिए एक नई समस्या पेश करता है जिनके मूल दृश्य स्क्रॉल करने योग्य (रीसाइक्लिंग व्यू की तरह) हैं। इन विचारों के लिए जब नीचे मार्जिन स्क्रॉल करना एक सफेद बार में दिखाई देगा (यदि सफेद पृष्ठभूमि रंग है)। यह उचित तेजी, के रूप में उन विचारों के लिए नेस्ट स्क्रॉल सुविधा उपकरण पट्टी ListView with last item cut

tl बाहर स्लाइड हो जाएगा; डॉ मैं गैर स्क्रॉल टुकड़े करने के लिए ?attr/actionBarSize के रूप में नीचे मार्जिन लगाने से कि समस्या के समाधान में काम किया है कि अंदर दिखाया जाता Framelayout। इससे पहले मैंने टूलबार की ऊंचाई ?attr/actionBarSize होने के लिए सेट की थी।

गतिविधि लेआउट:

 <android.support.design.widget.AppBarLayout 
      android:id="@+id/navContainer" 
      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" /> 

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

     <FrameLayout 
       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.CoordinatorLayout> 

टुकड़ा लेआउट:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="?attr/actionBarSize" 
      android:orientation="vertical"> 
      <!-- Further stuff here --> 
      <TextView android:id="@+id/label" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
      /> 
    </LinearLayout> 

केवल नकारात्मक पक्ष यह है मैं अभी का सामना करना पड़ा सफेद स्थान टुकड़ा लेआउट बनाने के दौरान एंड्रॉयड स्टूडियो के प्रीव्यूअर में दिखाया जा रहा है।

+0

यह मेरे लिए अच्छी तरह से काम किया! एक साइड-नोट के रूप में, यदि आपके टुकड़ों में से एक स्क्रोल करने योग्य रूट है जो ऐप बार को छुपाता है, तो यह पिछले (गैर-स्क्रोल करने योग्य) खंड पर वापस जाने के साथ छिपे रहेंगे, इसे फिर से दिखाने के लिए कोई रास्ता नहीं है। इस मुद्दे के लिए एक समाधान है [यहां उपलब्ध] (http://stackoverflow.com/q/30554824/1794631)। – rmorrin

1

आप अलग अलग Fragments अंदर का उपयोग करते हैं अपने CoordinatorLayout कुछ Fragments स्क्रॉल सामग्री है कि आप, इस समस्या का सामना करना पड़ेगा और कुछ स्क्रॉल नहीं करना चाहिए। आपके Toolbar में स्क्रॉलिंग झंडे हैं "scroll|enterAlways", जो पूर्व लेआउट के लिए ठीक है, लेकिन बाद वाले के लिए ठीक नहीं है। मेरा समाधान एक कस्टम AppBarLayout.Behavior है जो कस्टम टैग (contentShouldNotScrollTag) पर निर्भर स्क्रॉलिंग झंडे को स्विच करता है। लेआउट, जो इस तरह से स्क्रॉल नहीं करना चाहिए के लिए इस टैग को सेट करें:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="@string/contentShouldNotScrollTag"> 
    <!-- my non-scrollable Fragment layout --> 
</FrameLayout> 

नतीजतन, इस टुकड़ा की ऊंचाई स्क्रीन की ऊंचाई से अधिक नहीं होगा।

public class MyScrollBehavior extends AppBarLayout.Behavior { 
    private View content; 

    public MyScrollBehavior(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    @Override 
    public boolean onMeasureChild(CoordinatorLayout parent, AppBarLayout appBarLayout, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) { 
     if(content == null) { 
      content = parent.findViewById(R.id.container); 
     } 

     if(content != null) { 
      boolean shouldNotScroll = content.findViewWithTag(parent.getContext().getString(R.string.contentShouldNotScrollTag)) != null; 
      Toolbar toolbar = (Toolbar) appBarLayout.findViewById(R.id.toolbar); 
      AppBarLayout.LayoutParams params = 
        (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); 
      if (shouldNotScroll) { 
       params.setScrollFlags(0); 
       appBarLayout.setExpanded(true, true); 
      } else { 
       params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL 
         | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS); 
      } 
     } 

     return super.onMeasureChild(parent, appBarLayout, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed); 
    } 
} 
संबंधित मुद्दे