开发者

Pass touch event down through Views and ViewGroup

开发者 https://www.devze.com 2023-03-23 20:22 出处:网络
I have a FrameLayout wiht a ScrollView and a LinearLayout inside. Both ScrollView and LinearLayout have the same dimensions, so they are overlaid and the LinearLayout covers and hides the ScrollView.

I have a FrameLayout wiht a ScrollView and a LinearLayout inside. Both ScrollView and LinearLayout have the same dimensions, so they are overlaid and the LinearLayout covers and hides the ScrollView. The ScrollView has TextView and a Button inside itself.

This is the situation:

+FrameLayout
      +ScrollView
            + LinearLayout 1
                + TextView
                + Button
      +LinearLayout 2 

Sometimes the LinearLayout2, which is on the top, is animated and goes out of the screen. For layout reasons I can't set it to GONE and this is the problem. After the animation ends, the ScrollView is shown and I need to interact with the ScrollView, for example clicking the button and obviously scrolling, but all the events are always caught by the LinearLayout 2, because it always has the Visibility set to VISIBLE even if is actually hide out of the screen.

So, how can I pass the touch event down to the scrollview and its children?``

** EDIT **

This my XML. So you can understand better. Which is the idea? This layout is composed by 4 sliding drawer. When the user clicks on one of them, the drawer clicked goes up with animation and becomes a kind of header, the others go down out of the screen and they hide and the scrollview is visible ready to interact with the user.

For example: I click the second drawer, the third goes down, the disclaimer, the first goes up out of the screen and the second, which has been clicked goes at the top of the scree as an header. If I click again the second drawer, which is on the top now, I restore the initial layout as at the beginning, always with animation. To do that I add a Trasparent Layout, which has the same dimension of a drawer on the top, to handle click event, so I avoid to set a new layout whenever I animate the drawers.

What I want is to interact with the scrollview when it becomes visible and with all the stuff inside it.

PROBLEM: I can't set the drawers to GONE because the wieght parameter influences their height, but only to INVISIBLE. So, how can interact with the scrollview below?

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/programma_layout_root"
    android:layout_width="fill_parent" android:layout_height="fill_parent">


    <!-- SCROLLVIEW HIDDEN FIRST LAYER -->
    <ScrollView android:id="@+id/programma_content_scroll"  android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="top">

        <LinearLayout android:id="@+id/programma_layout_disclaimer_content"
            android:layout_height="fill_parent" android:layout_width="fill_parent"
            android:orientation="vertical" android:visibility="invisible">

            <TextView android:id="@+id/programma_layout_disclaimer_content_text"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:text="some text..." />

            <Button android:id="@+id/programma_layout_disclaimer_content_button"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:layout_gravity="center|bottom" android:text="CLICK" />

        </LinearLayout>

    </ScrollView>


    <!-- LAYOUT FOREGROUND SECOND LAYER -->
    <LinearLayout android:id="@+id/programma_layout_container" 
        android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:weightSum="19">

        <include android:id="@+id/header_placeholder" layout="@layout/header" />

        <!-- DISCLAIMER DRAWER -->
        <RelativeLayout android:id="@+id/programma_layout_disclaimer"
            android:layout_width="fill_parent" android:layout_height="fill_parent"
            android:layout_weight="4" >



        </RelativeLayout>

        <!-- FIRST DRAWER -->
        <RelativeLayout android:id="@+id/programma_layout_first"
            android:layout_width="fill_parent" android:layout_height="fill_parent"
            android:layout_weight="5" android:visibility="visible"
            >

            <!-- some stuff here (text, image...) -->

        </RelativeLayout>

        <!-- SECOND DRAWER -->
        <RelativeLayout android:id="@+id/programma_layout_second"
            android:layout_width="fill_parent" android:layout_height="fill_parent"
            android:layout_weight="5" 
            >

            <!-- some stuff开发者_StackOverflow here (text, image...) -->

        </RelativeLayout>

        <!-- THIRD DRAWER -->
        <RelativeLayout android:id="@+id/programma_layout_third"
            android:layout_width="fill_parent" android:layout_height="fill_parent"
            android:layout_weight="5" >

                    <!-- some stuff here (text, image...) -->               

        </RelativeLayout>


    </LinearLayout>

    <include android:id="@+id/header" layout="@layout/header"
        android:layout_gravity="top" />


</FrameLayout>
0

精彩评论

暂无评论...
验证码 换一张
取 消