2017-12-07 5 views
0

Ich habe eine Ansicht, die eine Spinner und eine Linearlayout int it hat. Die Linearlayout dient als übergeordnetes Element für ein untergeordnetes Layout. Das Kind-Layout wird programmatisch aufgeblasen. Die Kindansicht hat eine CardView mit TextView und eine Listenansicht in der CardView.Wie man Eltern- und Kindansicht scrollbar macht

Mein Problem ist, ich möchte die ganze Ansicht (mit Spinner und LinearLayout) Scrollbar und und Childview auch machen. Aber jedes Mal, wenn ich versuche, die Listenansicht innerhalb dieser CardView zu scrollen, scrollt die gesamte Ansicht. Wenn der Benutzer versucht, ListView zu blättern, sollte die Ansicht in meinem untergeordneten Layout nur scrollen.

Dies ist meine Mutter Layout:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:orientation="vertical"> 

    <com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner 
     android:id="@+id/shelfShareSelectionSpiiner" 
     android:layout_width="@dimen/_180sdp" 
     android:layout_height="@dimen/_40sdp" 
     android:layout_gravity="center" 
     android:hint="Select Category" /> 

    <LinearLayout 
     android:id="@+id/shelfShareLinearlayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:layout_marginLeft="@dimen/_5sdp" 
     android:layout_marginStart="@dimen/_5sdp" 
     android:padding="@dimen/_10sdp" /> 


</LinearLayout> 
</ScrollView> 

Das ist mein Kind Ansicht:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
    android:id="@+id/shelfShareMasterLL" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/frontalRodShareCardView" 

     android:layout_width="@dimen/_292sdp" 
     android:layout_height="@dimen/_250sdp" 
     android:layout_marginLeft="@dimen/_4sdp" 
     android:layout_marginRight="@dimen/_4sdp" 
     android:layout_marginStart="@dimen/_4sdp" 
     android:layout_marginTop="@dimen/_8sdp" 
     app:cardElevation="@dimen/_3sdp" 
     app:cardUseCompatPadding="true" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent"> 

     <RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/shelfShareMasterRL" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <TextView 
       android:id="@+id/shelfShareHeadingTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 

       android:layout_marginLeft="@dimen/_10sdp" 
       android:layout_marginTop="@dimen/_10sdp" 
       android:text="Frontal Rod Share" 
       android:textSize="@dimen/_10ssp" /> 


      <ListView 
       android:id="@+id/shelfShareProductListView" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

      </ListView> 

     </RelativeLayout> 

    </android.support.v7.widget.CardView> 

</LinearLayout> 

Dank.

+0

Haben Sie versucht, NestedScrollview anstelle von ScrollView zu verwenden? –

+0

Ja, habe ich. Ich habe verschachtelte Scrollview mit Scrollview in meinem übergeordneten Layout ersetzt, aber es hat nicht funktioniert. – 3iL

Antwort

2

Ich denke, um dies zu erreichen, müssen Sie ontouchListener für ListView implementieren. Und in diesem Listener müssen Sie verhindern, dass der Parent-Scrollview-Touchevent ausgeführt wird.

shelfShareProductListView.setOnTouchListener(new OnTouchListener() { 
    // Setting on Touch Listener for handling the touch inside ScrollView 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     // Disallow the touch request for parent scroll on touch of child view 
     v.getParent().requestDisallowInterceptTouchEvent(true); 
     return false; 
    } 
}); 
+0

Vielen Dank! Das funktioniert wie Charme :) – 3iL

Verwandte Themen