Search code examples
androidlayoutscrollviewclickable

layout is not clickable outside the scrollview in android


I have a ScrollView and I want to be clickable and scrollable. Relative layout is my root layout. Here is my code:

<RelativeLayout
    android:clickable="true"
    android:clipToPadding="false"
    android:id="@+id/cardOpt2"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content">

    <ScrollView
        android:clickable="false"
        android:fillViewport="true"
        android:layout_centerInParent="true"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">

        <TextView
            android:id="@+id/btnOpt2"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content" />
    </ScrollView>
</RelativeLayout>

Solution

  • You should use your scrollView as root layout and set :

    android:layout_height="match_parent"
    android:layout_height="wrap_content"
    

    Do this :

     <ScrollView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:clickable="false"
              android:fillViewport="true"
              android:clipToPadding="false">
    
                <RelativeLayout
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:clickable="true"
                   android:clipToPadding="false"
                   android:id="@+id/cardOpt2">
    
                   <TextView
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:id="@+id/btnOpt2" />
    
                <RelativeLayout/>
    </ScrollView>