鍍金池/ 問(wèn)答/Android/ 請(qǐng)教一個(gè)RecyclerView的item側(cè)滑和點(diǎn)擊沖突的問(wèn)題

請(qǐng)教一個(gè)RecyclerView的item側(cè)滑和點(diǎn)擊沖突的問(wèn)題

item的布局引入了側(cè)滑刪除后,側(cè)滑出來(lái)的按鈕可以正常點(diǎn)擊刪除,但是adapter的setOnItemClickListener()方法無(wú)效,點(diǎn)擊item不響應(yīng)了該怎么解決呢?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/ll_my_post"
    android:orientation="vertical">

    <!--側(cè)滑刪除框架-->
      <com.guanaj.easyswipemenulibrary.EasySwipeMenuLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/content_click"
          app:contentView="@+id/content"
          app:leftMenuView="@+id/left"
          app:rightMenuView="@+id/right">

          <LinearLayout
              android:id="@+id/content"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:padding="5dp">

              <TextView
                  android:id="@+id/tv_my_post_content"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="RNG.M九連勝穩(wěn)固榜首,Song連奪..." />

              <RelativeLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_margin="5dp">

                  <TextView
                      android:id="@+id/temp_tv"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_centerVertical="true"
                      android:text="剛剛發(fā)布于" />

                  <TextView
                      android:id="@+id/tv_host_name"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_centerVertical="true"
                      android:layout_toRightOf="@id/temp_tv"
                      android:text="主播名字"
                      android:textColor="@color/color_orange" />

                  <TextView
                      android:id="@+id/tv_mypost_comments_count"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_alignParentRight="true"
                      android:layout_centerVertical="true"
                      android:text="550" />

                  <ImageView
                      android:padding="3dp"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_centerVertical="true"
                      android:layout_toLeftOf="@id/tv_mypost_comments_count"
                      android:src="@mipmap/comments" />

                  <TextView
                      android:id="@+id/tv_like_count"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_centerVertical="true"
                      android:layout_toLeftOf="@id/tv_mypost_comments_count"
                      android:paddingRight="30dp"
                      android:text="220" />

                  <ImageView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_centerVertical="true"
                      android:layout_margin="3dp"
                      android:layout_toLeftOf="@id/tv_like_count"
                      android:src="@mipmap/heart" />

              </RelativeLayout>

          </LinearLayout>

          <LinearLayout
              android:id="@+id/right"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:background="@color/colorRed"
              android:orientation="horizontal">

              <TextView
                  android:id="@+id/tv_my_message_delete"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  android:padding="20dp"
                  android:text="刪除"
                  android:textColor="@color/white" />

          </LinearLayout>

      </com.guanaj.easyswipemenulibrary.EasySwipeMenuLayout>

</LinearLayout>
    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        //TODO:加了側(cè)滑刪除,點(diǎn)擊item無(wú)效
        Toast.makeText(this, "點(diǎn)擊l"+position, Toast.LENGTH_SHORT).show();

    }
回答
編輯回答
笨笨噠

xml是item的布局吧?
是不是EasySwipeMenuLayout的onclick或者ontouch方法,return true,把點(diǎn)擊事件攔截了?

2018年8月15日 01:54