2017-12-07 1 views
0

나는 SpinnerLinearlayout int가있는보기가 있습니다. Linearlayout은 하위 레이아웃의 부모 역할을합니다. 자식 레이아웃은 프로그래밍 방식으로 확장됩니다. 하위보기는 CardView이고 TextView이고 목록보기는 CardView입니다.부모 및 자식보기를 스크롤 할 수있게 만드는 방법

내 문제는 스크롤 할 수있는 전체보기 (SpinnerLinearLayout보기)와 childview도 만들고 싶습니다. 그러나 그 안에서 CardView 안에리스트 뷰를 스크롤하려고 할 때마다 전체보기가 스크롤됩니다. 사용자가 ListView를 스크롤하려고하면 내 자식 레이아웃 내부의보기 만 스크롤해야합니다.

이 내 부모 레이아웃입니다 :

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

감사 :

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

이 내 자식이다.

+0

ScrollView 대신 NestedScrollview를 사용해 보셨나요? –

+0

예, 있습니다. 부모 레이아웃에서 중첩 된 scrollview를 scrollview로 대체했지만 작동하지 않았습니다. – 3iL

답변

2

나는 이것을 달성하기 위해, 당신은 listview를 위해 ontouchListener를 구현해야한다고 생각한다. 이 수신기에서 부모 스크롤 뷰를 방지해야합니다.

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

정말 고마워요! 이것은 매력처럼 작동합니다 :) – 3iL

관련 문제