最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android RecyclerView實現(xiàn)滑動刪除

 更新時間:2020年07月28日 17:19:32   作者:夜行俠~@  
這篇文章主要為大家詳細介紹了Android RecyclerView實現(xiàn)滑動刪除,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了RecyclerView實現(xiàn)滑動刪除的具體代碼,供大家參考,具體內容如下

package com.example.demo;
 
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
 
import android.graphics.Canvas;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author Huang xudong
 * @date 2020/7/26
 */
public class MainActivity extends AppCompatActivity {
 private RecyclerView recyclerView;
 
 private List list=new ArrayList();
 
 class MyAdpter extends RecyclerView.Adapter<MyAdpter.ViewHolder>{
 
  class ViewHolder extends RecyclerView.ViewHolder{
   private TextView textView;
   private LinearLayout linearLayout;
 
   public ViewHolder(@NonNull View itemView) {
    super(itemView);
    linearLayout=itemView.findViewById(R.id.ll_main);
    textView=itemView.findViewById(R.id.tv_main);
   }
  }
 
  @NonNull
  @Override
  public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
   View inflate = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_demo,parent, false);
   return new ViewHolder(inflate);
  }
 
  @Override
  public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
 
  }
 
  @Override
  public int getItemCount() {
   return list.size();
  }
 }
 
 class CallBack extends ItemTouchHelper.Callback{
  @Override
  public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
   return makeMovementFlags(0,ItemTouchHelper.LEFT);
  }
 
  @Override
  public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
   return false;
  }
 
  @Override
  public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
   /**
    * call max distance start onSwiped call
    */
  }
 
  @Override
  public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
 
 
   if (actionState==ItemTouchHelper.ACTION_STATE_SWIPE){
    /**
     * get {@link TextView#getWidth()}
     */
    ViewGroup viewGroup= (ViewGroup) viewHolder.itemView;
    TextView textView = (TextView) viewGroup.getChildAt(1);
    ViewGroup.LayoutParams layoutParams = textView.getLayoutParams();
    if (Math.abs(dX)<=layoutParams.width){
     /**
      * move {@link RecyclerView.ViewHolder} distance
      */
     viewHolder.itemView.scrollTo((int) -dX,0);
     /**
      * callAction or register click bind view
      */
    }
   }
  }
 }
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 
  recyclerView=findViewById(R.id.rv_main);
  list.add(1);
  list.add("2");
  MyAdpter myAdpter=new MyAdpter();
  LinearLayoutManager linearLayoutManager=new LinearLayoutManager(getApplicationContext());
  linearLayoutManager.setOrientation(RecyclerView.VERTICAL);
  recyclerView.setLayoutManager(linearLayoutManager);
  recyclerView.setAdapter(myAdpter);
  ItemTouchHelper itemTouchHelper=new ItemTouchHelper(new CallBack());
  itemTouchHelper.attachToRecyclerView(recyclerView);
 }
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".MainActivity">
 
 <androidx.recyclerview.widget.RecyclerView
  android:id="@+id/rv_main"
  app:layout_constraintLeft_toLeftOf="parent"
  app:layout_constraintRight_toRightOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  app:layout_constraintBottom_toBottomOf="parent"
  android:layout_width="0dp"
  android:layout_height="0dp">
 
 </androidx.recyclerview.widget.RecyclerView>
 
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:paddingBottom="10dp"
 xmlns:app="http://schemas.android.com/apk/res-auto">
 
 <LinearLayout
  android:id="@+id/ll_main"
  android:background="@color/colorPrimaryDark"
  app:layout_constraintTop_toTopOf="parent"
  app:layout_constraintLeft_toLeftOf="parent"
  app:layout_constraintRight_toRightOf="parent"
  android:layout_width="0dp"
  android:layout_height="200dp"
  android:orientation="horizontal">
 
 </LinearLayout>
 
 <TextView
  android:textColor="#ffffff"
  android:gravity="center"
  android:id="@+id/tv_main"
  android:textSize="34sp"
  android:text="刪 除"
  android:background="@color/colorAccent"
  app:layout_constraintLeft_toRightOf="@id/ll_main"
  app:layout_constraintTop_toTopOf="@id/ll_main"
  app:layout_constraintBottom_toBottomOf="@id/ll_main"
  android:layout_width="180dp"
  android:layout_height="0dp">
 
 </TextView>
 
 
 
</androidx.constraintlayout.widget.ConstraintLayout>

效果圖:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Android中SharedPreference使用實例講解

    Android中SharedPreference使用實例講解

    這篇文章主要介紹了Android中SharedPreference使用方法,實現(xiàn)登陸界面記住密碼功能,感興趣的小伙伴們可以參考一下
    2016-01-01
  • Android 使用mediaplayer播放res/raw文件夾中的音樂的實例

    Android 使用mediaplayer播放res/raw文件夾中的音樂的實例

    這篇文章主要介紹了Android 使用mediaplayer播放res/raw文件夾中的音樂的實例的相關資料,需要的朋友可以參考下
    2017-04-04
  • Android App在ViewPager中使用Fragment的實例講解

    Android App在ViewPager中使用Fragment的實例講解

    這篇文章主要介紹了Android App在ViewPager中使用Fragment的實例講解,ViewPager組件主要被用來制作滑動切換效果,需要的朋友可以參考下
    2016-03-03
  • Android控件View打造完美的自定義側滑菜單

    Android控件View打造完美的自定義側滑菜單

    這篇文章主要介紹了Android控件View打造完美的自定義側滑菜單的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android仿小米時鐘效果

    Android仿小米時鐘效果

    這篇文章主要為大家詳細介紹了Android仿小米時鐘效果的相關資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Android自定義View仿微博運動積分動畫效果

    Android自定義View仿微博運動積分動畫效果

    這篇文章主要為大家詳細介紹了Android自定義View仿微博運動積分動畫效果,開啟了自定義view學習旅程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-05-05
  • android使用handlerthread創(chuàng)建線程示例

    android使用handlerthread創(chuàng)建線程示例

    這篇文章主要介紹了android使用handlerthread創(chuàng)建線程,講解了這種方式的好處及為什么不使用Thread類的原因
    2014-01-01
  • Android布局ConstraintLayout代碼修改約束及輔助功能

    Android布局ConstraintLayout代碼修改約束及輔助功能

    這篇文章主要為大家介紹了Android布局ConstraintLayout代碼修改約束及輔助功能示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-09-09
  • Android自定義View實現(xiàn)開關按鈕

    Android自定義View實現(xiàn)開關按鈕

    android 自定義view知識非常廣泛,難以讓人掌握。但是也是andoroid進階學習的必經之路。下面通過本文給大家介紹Android自定義View實現(xiàn)開關按鈕的知識,非常不錯,感興趣的朋友一起看看吧
    2016-11-11
  • Android布局之RelativeLayout相對布局

    Android布局之RelativeLayout相對布局

    RelativeLayout是相對布局控件:以控件之間相對位置或相對父容器位置進行排列,下面通過本文給大家介紹Android布局之RelativeLayout相對布局,涉及到android relativelayout相對布局相關知識,對android relativelayout相對布局相關知識,感興趣的朋友一起學習吧
    2015-12-12

最新評論

句容市| 馆陶县| 海兴县| 余庆县| 沭阳县| 丽水市| 郸城县| 江达县| 新丰县| 十堰市| 盘山县| 莎车县| 手游| 长阳| 余庆县| 桦南县| 赤壁市| 内丘县| 岗巴县| 吴桥县| 绥芬河市| 吉隆县| 安仁县| 石泉县| 柘荣县| 衡阳县| 桑日县| 新闻| 通州区| 土默特左旗| 都江堰市| 宁明县| 武穴市| 竹山县| 沭阳县| 吐鲁番市| 寻甸| 崇信县| 宜章县| 兰西县| 炉霍县|