daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

Bottom view with list selector changes state when top view is pressed #252

Open MelerosPaw opened 8 years ago

MelerosPaw commented 8 years ago

My bottom view contains two FrameLayouts with an ImageView each. These FrameLayout have a color selector for the states pressed=true y pressed=false. When the top view is open, and you click on it, the bottom view's last child changes its state to pressed, although it doesn't trigger its onClickListener, just changes its state.

If I add a new FrameLayout with another list selector at the end of the bottom view, this one changes its state instead. So it's always the last hchild of the bottom view that changes its state to pressed when I press the top view. How so?

I solved it by adding an extra FrameLayout with height and width=0 as last child of the bottom view, so it's not visible but the status doesn't change on any of the visible views. This is the code:

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.daimajia.swipe.SwipeLayout
            android:id="@+id/news.swipe"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <FrameLayout
                    android:id="@+id/news.fav"
                    android:layout_width="56dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/button_fav_background"
                    android:clickable="true">

                    <ImageView
                        android:layout_width="32dp"
                        android:layout_height="32dp"
                        android:layout_gravity="center"
                        android:background="@color/white" />

                </FrameLayout>

                <FrameLayout
                    android:id="@+id/news.share"
                    android:layout_width="56dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/button_share_background"
                    android:clickable="true">

                    <ImageView
                        android:layout_width="32dp"
                        android:layout_height="32dp"
                        android:layout_gravity="center"
                        android:background="@color/white" />

                </FrameLayout>

                <!--Extra layout -->
                <FrameLayout
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:clickable="true">

              </FrameLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="32dp"
                android:layout_marginStart="32dp"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:text="Title" />

            </LinearLayout>

        </com.daimajia.swipe.SwipeLayout>

    </FrameLayout>