2016-07-12 10 views
5

साथ उड़ रहा अंदर एक NestedScrollView के साथ एक नीचे चादर है (नीचे देखें)। जब मैं एक एफएबी बटन दबाता हूं, तो मैं इस NestedScrollView में कुछ हिस्सों को अदृश्य बनाना चाहता हूं। लेकिन जब मैं कुछ लाइनरलेआउट दृश्यता को बदलने के लिए बदलता हूं, तो नीचे की तरफ से नीचे की तरफ उड़ने वाली बोतलें। यहाँ देखें:BottomSheet दृश्यता परिवर्तन

enter image description here

आप https://github.com/Tanrikut/BottomSheetExample

से पूरे कोड प्राप्त कर सकते हैं मेरे परिवर्तन दृश्यता विधि: इस

<?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:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:behavior_peekHeight="120dp" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior" 
    android:id="@+id/bottom_sheet_main"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="28dp" 
      android:background="@android:color/white" 
      android:animateLayoutChanges="true" 
      android:orientation="vertical" 
      > 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:paddingLeft="10dp" 
       android:paddingStart="10dp" 
       android:paddingTop="@dimen/activity_horizontal_margin"> 

       <TextView 
        style="@style/TextAppearance.AppCompat.Headline" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Dandelion Chocolate" 
        android:id="@+id/title" /> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="@dimen/activity_horizontal_margin" 
        android:layout_marginTop="16dp" 
        android:orientation="horizontal" 
        android:id="@+id/subtitleLayout"> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:id="@+id/subtitle" 
         android:text="Subtitle" /> 

       </LinearLayout> 


      </LinearLayout> 


      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:padding="@dimen/activity_horizontal_margin" 
       android:id="@+id/coordinateLayout"> 

       <ImageButton 
        android:layout_width="24dp" 
        android:layout_height="24dp" 
        android:alpha="0.36" 
        android:src="@drawable/ic_room_24dp" 
        android:background="@null" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="@dimen/activity_horizontal_margin" 
        android:layout_marginStart="@dimen/activity_horizontal_margin" 
        android:text="740, Valencia St, San Francisco, CA" 
        android:textColor="@android:color/primary_text_light" 
        android:id="@+id/bottom_sheet_coordinate" /> 

      </LinearLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:padding="@dimen/activity_horizontal_margin" 
       android:id="@+id/timeLayout"> 

       <ImageButton 
        android:layout_width="24dp" 
        android:layout_height="24dp" 
        android:alpha="0.36" 
        android:src="@drawable/ic_query_builder_24dp" 
        android:background="@null" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="@dimen/activity_horizontal_margin" 
        android:layout_marginStart="@dimen/activity_horizontal_margin" 
        android:text="Wed, 10 AM - 9 PM" 
        android:textColor="@android:color/primary_text_light" 
        android:id="@+id/bottom_sheet_time" /> 

      </LinearLayout> 


     </LinearLayout> 

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

आप कहाँ बुला रहे हैं changeVisibility() विधि एक आप एंड्रॉयड का उपयोग कर रहे के पूर्वजों कर रहे हैं? – Lawrance

+0

एक फैब बटन – Tanrikut

उत्तर

0

हो सकता है:

private void changeVisibility() { 
    subtitleLayout.setVisibility(View.GONE); 

    coordinateLayout.setVisibility(View.GONE); 
    timeLayout.setVisibility(View.GONE); 

} 

मेरे NestedScrollView एक्सएमएल आपको मदद कर सकते हैं! मैं तो एक जवाब के रूप में यह पोस्टिंग

Here

for slide layout something same as bottom sheet but good

+0

के clicklistener अंदर मैं तुम्हें क्या सुझाव है के बारे में स्पष्ट नहीं कर रहा हूँ। क्या आप एक तल की चादर के अंदर दृश्यता बदलने के बजाय एकाधिक तल चादरें रखने का सुझाव देते हैं? – Tanrikut

+0

यह आपके ऊपर है, लेकिन मैं कोड नीचे की चादरों के लिए एक रास्ता सुझा रहा था, इसके बजाय आप स्लाइड करने योग्य लेआउट का उपयोग मेरे संपादित उत्तर को देख सकते हैं क्योंकि नीचे की चादरें उपयोग करने के लिए इतनी अच्छी नहीं हैं (मेरे परिप्रेक्ष्य के लिए) –

0

BottomSheetBehavior अपने स्वयं के व्यवहार है जिसके द्वारा आप-अपने परिणाम प्राप्त कर सकते हैं टिप्पणी नहीं कर सकता। नीचे बॉटलशीट का व्यवहार है।

STATE_DRAGGING, STATE_SETTLING, STATE_EXPANDED, STATE_COLLAPSED, STATE_HIDDEN

किसी भी लेआउट की दृश्यता का प्रयोग न करें।

की तरह अपने कोड में इस व्यवहार का उपयोग करें:

fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       int behaviorState = bottomSheetBehavior.getState(); 
       if (behaviorState == BottomSheetBehavior.STATE_EXPANDED) { 
        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); 
       } else { 
        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); 
       } 
      } 
}); 
+0

मैं दृश्यता बदलने की कोशिश नहीं कर रहा हूं सबसे निचली शीट। मैं उस नीचे की चादर के अंदर दिखाई देने वाली चीज़ों को बदलने की कोशिश कर रहा हूं। – Tanrikut

7

मैं इस में भाग, यह पता लगाने की क्या कारण था कुछ समय लिया।

यह है क्योंकि आप एंड्रॉयड का उपयोग कर रहे हैं: animateLayoutChanges, जो या तो BottomSheetBehavior या CoordinatorLayout में एक बग सतहों।

यह निकालें और BottomSheet अपने आप ही एनिमेट बंद हो जाएगा, जब यह नहीं करना चाहिए। एक फिक्स नहीं, लेकिन कम से कम एक कामकाज।

-

अद्यतन:

बाहर कर देता है कि यदि आप "animateLayoutChanges" प्रोग्राम के रूप में उपयोग करने के लिए LayoutTransition उदाहरण सेटिंग के द्वारा सक्षम है, तो आप उस पर एक ध्वज सेट कर सकते हैं कि यह विचारों के साथ खिलवाड़ करने से रोक देगा कि पर (उर्फ: अपने BottomSheet कंटेनर): animateLayoutChanges:

LayoutTransition transition = new LayoutTransition(); 
transition.setAnimateParentHierarchy(false); 
yourLinearLayoutThatNeedsLayoutAnimation.setLayoutTransition(transition); 
+0

यह मैं –

+0

के लिए काम किया यह वास्तव में क्या समस्या का हल है! - धन्यवाद! यह समस्या अभी भी वर्तमान समर्थन lib v25.0.1 में मौजूद है – koesclem

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