2017-04-08 5 views
1

dieses Layout mit dem Namen Songlist meiner XML ist:BottomSheetBehavior ist kein Kind von CoordinatorLayout

enter image description here

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

     <LinearLayout 
      android:id="@+id/viewA" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="0.6" 
      android:background="@android:color/holo_purple" 
      android:orientation="horizontal"/> 

     <android.support.v4.widget.NestedScrollView 
      android:id="@+id/bottom_sheet" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@android:color/holo_blue_bright" 
      app:layout_behavior="android.support.design.widget.BottomSheetBehavior" 
      > 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
       <ListView 
        android:id="@+id/list" 
        android:layout_width="match_parent" 
        android:layout_height="308dp" 
        /> 
      </LinearLayout> 

     </android.support.v4.widget.NestedScrollView> 
    </LinearLayout> 
    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:clickable="true" 
     android:src="@drawable/personlog" 
     app:layout_anchor="@id/viewA" 
     app:layout_anchorGravity="bottom|center"/> 

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

und das ist mein Fragment, das dieses Layout enthält:

public class SongList extends Fragment { 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

     View view = inflater.inflate(R.layout.songlist,container,false); 

     textView=(TextView)view.findViewById(R.id.txt); 

     View bottomSheet = view.findViewById(R.id.bottom_sheet); 
     BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); 
     bottomSheetBehavior.setPeekHeight(200); 
return view;} 
} 

aber wenn Mittagessen die App geben Sie mir diesen Fehler:

java.lang.IllegalArgumentException: The view is not a child of CoordinatorLayout 

aus dieser Zeile:

BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); 

, wie dieses Problem beheben? scheint alles gut funktionieren, aber diesen Fehler geben ... wenn jemand bitte

+0

also wie kann dieses Layout mit echter Weise gemacht werden? Wenn Sie eine Lösung haben, antworten Sie bitte – Erf

+0

Ich füge NestedScrollView in CoordinatorLayout aber immer noch das gleiche Problem – Erf

+0

kann Ihren Punkt verstehen. Wenn Sie mir helfen wollen, bitte beantworten Sie meine Frage nicht kommentieren dann sagen Sie mir, wo Code geändert werden muss, was oder etwas so. Tnx – Erf

Antwort

3

Die BottomSheetBehavior ist

Ein Interaktionsverhalten Plugin für ein Kind Ansicht von CoordinatorLayout helfen kann, um es als Bodenblech zu arbeiten.

Im Moment Sie unteres Blatt NestedScrollView ist ein Kind von LinearLayout. Also einfach die äußerste LinearLayout komplett fallen lassen.

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/viewA" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="0.6" 
     android:background="@android:color/holo_purple" 
     android:orientation="horizontal"/> 

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/bottom_sheet" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/holo_blue_bright" 
     app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 

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

      <ListView 
       android:id="@+id/list" 
       android:layout_width="match_parent" 
       android:layout_height="308dp" /> 
     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:clickable="true" 
     android:src="@drawable/personlog" 
     app:layout_anchor="@id/viewA" 
     app:layout_anchorGravity="bottom|center" /> 
</android.support.design.widget.CoordinatorLayout> 

Aber jetzt haben Sie einige Probleme mit dem unteren Blatt, das Sie implementieren möchten. Erstens sollten Sie wrap_content nicht mit einer Bildlaufansicht verwenden. Zweitens sollten Sie keine Listenansicht in einer Bildlaufansicht verwenden, da sie ein eigenes Scrollen implementiert. Sie können dies möglicherweise vereinfachen, indem Sie die Listenansicht nur als unteres Blatt verwenden.

Verwandte Themen