2016-07-12 22 views
5

Ich habe ein unteres Blatt mit einer NestedScrollView innerhalb (siehe unten). Wenn ich auf eine FAB-Taste drücke, möchte ich einige Teile in dieser NestedScrollView unsichtbar machen. Aber wenn ich die Sichtbarkeit einiger Linearlayouts auf GONE ändere, fliege ich von oben nach unten. Siehe hier:BottomSheet fliegen weg mit Änderung der Sichtbarkeit

enter image description here

Sie können den gesamten Code erhalten von https://github.com/Tanrikut/BottomSheetExample

Meine Änderung Sichtbarkeit Methode:

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

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

} 

Meine NestedScrollView xml:

<?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

Wo Sie Aufruf changeVisibility() -Methode? – Lawrance

+0

In einem Klick-Listener einer Fab-Taste – Tanrikut

Antwort

0

dies auch sein mag kann dir helfen! Ich kann nicht so äußern sie als Antwort Entsendung

Here

for slide layout something same as bottom sheet but good

+0

Ich bin nicht klar, was Sie vorschlagen. Schlägst du vor, mehrere untere Blätter zu haben, anstatt die Sichtbarkeit in einem unteren Blatt zu ändern? – Tanrikut

+0

sein bis zu Ihnen, aber ich schlug einen Ausweg vor, um untere Blätter zu kodieren, stattdessen können Sie gleitbares Layout verwenden siehe meine bearbeitete Antwort, weil untere Blätter nicht so gut zu verwenden sind (wie für meine Perspektive lol) –

0

BottomSheetBehavior sein eigenes Verhalten haben, mit denen Sie entsprechende Ergebnis bekommen. Es folgen die Verhaltensweisen der unteren Blattlage.

STATE_DRAGGING, STATE_SETTLING, STATE_EXPANDED, STATE_COLLAPSED, STATE_HIDDEN.

Verwenden Sie keine Sichtbarkeit von Layouts.

Verwenden Sie dieses Verhalten im Code wie:

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

Ich versuche nicht, Sichtbarkeit zu ändern Bodenfolie. Ich versuche zu ändern, was in diesem unteren Blatt sichtbar ist. – Tanrikut

7

ich in diese lief, dauerte eine Weile, um herauszufinden, was die Ursache war.

Es ist, weil Sie android: animateLayoutChanges verwenden, die einen Fehler in BottomSheetBehavior oder CoordinatorLayout zeigt.

Entfernen Sie es und das BottomSheet wird nicht mehr selbst animieren, wenn es nicht sollte. Keine Lösung, aber zumindest ein Workaround.

-

Update:

Es stellte sich heraus, dass, wenn Sie „animateLayoutChanges“ programmatisch aktivieren, indem Sie die LayoutTransition Instanz einstellen, verwenden Sie eine Flagge auf sie einstellen können, dass sie von Messing mit Ansichten verhindern wird, dass sind Vorfahren der ein verwenden Sie android: animateLayoutChanges auf (auch bekannt als: Ihr BottomSheet Container):

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

Das funktionierte für mich –

+0

Das ist genau das, was das Problem löst! - Danke! Dieses Problem ist immer noch in der aktuellen Support-Bibliothek v25.0.1 vorhanden – koesclem