Android 滑动视图必须在触摸其他网格项或释放触摸时转到



我想在拖动图像视图时实现一个网格视图(在图像视图下方具有图像视图和 2 个 txtview(,用户可以查看文本视图,但当用户删除拖动时,txtview 必须消失,所有其他网格项文本视图也必须消失我使用了编译"com.daimajia.swipelayout:library:1.2.0@aar">我的 XML 文件是

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relaGrid"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorgry"
    android:orientation="vertical" >
    <com.daimajia.swipe.SwipeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/sample1"
        android:layout_width="match_parent" android:layout_height="150sp">
        <!-- Bottom View Start-->
        <LinearLayout
            android:background="#66ddff00"
            android:id="@+id/bottom_wrapper"
            android:layout_width="match_parent"
            android:weightSum="1"
            android:orientation="vertical"
            android:layout_height="match_parent">
            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView" />
            <!--What you want to show-->
        </LinearLayout>
        <!-- Bottom View End-->
        <!-- Surface View Start -->
        <LinearLayout
            android:padding="10dp"
            android:background="#ffffff"
            android:orientation="vertical"
            android:layout_width="150sp"
            android:layout_height="150sp">
            <ImageView
                android:id="@+id/img2"
                android:layout_width="150sp"
                android:layout_height="150sp"
                android:src="@mipmap/ic_launcher" />
            <!--What you want to show in SurfaceView-->
        </LinearLayout>
        <!-- Surface View End -->
    </com.daimajia.swipe.SwipeLayout>
    <TextView
        android:id="@+id/txt2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/sample1"
        android:text="TextView"        android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" />
</RelativeLayout>

和适配器 Java 文件中

  holder.swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
..........
  public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
                    bottom_wrapper.setVisibility(View.GONE);
                    System.out.println("TOUCH FINISH");
                    layout.setVisibility(View.VISIBLE);
                    System.out.println("xvel "+xvel+"   yvel "+yvel+"'");
                }

如果要删除所有网格项,则可以在触摸完成事件时隐藏网格视图的可见性。gridview.setVisibility(View.GONE(;

最新更新