Android中RecyclerView拖拽、侧删功能的实现代码

废话不多说,下面展示一下效果。

这是GridView主文件实现。

public class GridViewActivity extends AppCompatActivity {
  RecyclerView mRecyclerView;
  List<String> mStringList;
  RecyclerAdapter mRecyAdapter;
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recyclerview);
    initView();
    initRecy();
  }
  private void initView() {
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mRecyclerView = (RecyclerView) findViewById(R.id.view_recycler);
  }
  private void initRecy() {
    if (mStringList == null) {
      mStringList = new ArrayList<>();
    }
    mStringList.addAll(DataManager.getData(20 - mStringList.size()));
    mRecyAdapter = new RecyclerAdapter(R.layout.item_gridview, mStringList, true);
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 4));
    mRecyclerView.addItemDecoration(new DividerGriItemDecoration(this));
    mRecyclerView.setHasFixedSize(true);
    RecyItemTouchHelperCallback itemTouchHelperCallback = new RecyItemTouchHelperCallback(mRecyAdapter, false, true);
    final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback);
    itemTouchHelper.attachToRecyclerView(mRecyclerView);
    mRecyclerView.addOnItemTouchListener(new OnRecyclerItemClickListener(mRecyclerView) {
      @Override
      public void onItemClick(RecyclerView.ViewHolder viewHolder) {
        RecyclerAdapter.ViewHolder viewHolder1 = (RecyclerAdapter.ViewHolder) viewHolder;
        String tvString = viewHolder1.mTextView.getText().toString();
        Toast.makeText(GridViewActivity.this, "碰了一下 " + tvString, Toast.LENGTH_SHORT).show();
      }
      @Override
      public void onLongClick(RecyclerView.ViewHolder viewHolder) {
        RecyclerAdapter.ViewHolder viewHolder1 = (RecyclerAdapter.ViewHolder) viewHolder;
        String tvString = viewHolder1.mTextView.getText().toString();
        Toast.makeText(GridViewActivity.this, "长按不放可以拖动!", Toast.LENGTH_SHORT).show();
        if (viewHolder.getLayoutPosition() != 0) {
          itemTouchHelper.startDrag(viewHolder);
        }
      }
    });
    mRecyclerView.setAdapter(mRecyAdapter);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
      finish();
    }
    return super.onOptionsItemSelected(item);
  }
}

代码不难理解,就是activity里面设置一大堆初始化的东西。RecyclerView 初始化,setLayoutManager、addItemDecoration、setHasFixedSize、itemTouchHelper、addOnItemTouchListener、setAdapter。拖拽效果关键代码是itemTouchHelper.startDrag(viewHolder)。其他都围绕着它来转。

然后具体看看各个设置。

DataManager

public class DataManager {
  private static List<String> sStringList = Arrays.asList("语文", "数学", "英语", "政治",
      "历史", "化学", "生物", "地理", "体育", "音乐");
  public static final List<String> getData(int number) {
    List<String> stringList = new ArrayList<>();
    for (int i = 0; i < number; i++) {
      stringList.add(sStringList.get(i % sStringList.size()));
    }
    return stringList;
  }
}

DividerGriItemDecoration 这个绘画了item的边线

public class DividerGriItemDecoration extends RecyclerView.ItemDecoration {
  private static final int[] ATTRS = new int[]{android.R.attr.listDivider};
  private Drawable mDivider;
  private int lineWidth = 1;
  public DividerGriItemDecoration(GridViewActivity gridViewActivity) {
    final TypedArray array = gridViewActivity.obtainStyledAttributes(ATTRS);
    mDivider = array.getDrawable(0);
    array.recycle();
  }
  public DividerGriItemDecoration(int color) {
    mDivider = new ColorDrawable(color);
  }
  @Override
  public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    drawHorizontal(c, parent);
    drawVertical(c, parent);
  }
  private void drawHorizontal(Canvas c, RecyclerView parent) {
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
      final View child = parent.getChildAt(i);
      final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
      final int left = child.getLeft() - params.leftMargin;
      final int right = child.getRight() + params.rightMargin + lineWidth;
      final int top = child.getBottom() + params.bottomMargin;
      final int bottom = top + lineWidth;
      mDivider.setBounds(left, top, right, bottom);
      mDivider.draw(c);
    }
  }
  private void drawVertical(Canvas c, RecyclerView parent) {
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
      final View child = parent.getChildAt(i);
      final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
      final int top = child.getTop() - params.topMargin;
      final int bottom = child.getBottom() + params.bottomMargin;
      final int left = child.getRight() + params.rightMargin;
      final int right = left + lineWidth;
      mDivider.setBounds(left, top, right, bottom);
      mDivider.draw(c);
    }
  }
  @Override
  public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    outRect.set(0, 0, lineWidth, lineWidth);
  }
}

RecyclerAdapter 适配器,和ui建立连接

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
  private int item_layout;
  private List<String> mDataList;
  private List<Integer> mInts;
  private boolean isFirstSpecial;
  public RecyclerAdapter(int item_gridview, List<String> dataList, boolean isFisrtSpecial) {
    this(item_gridview, dataList);
    this.isFirstSpecial = isFisrtSpecial;
  }
  public RecyclerAdapter(int item_gridview, List<String> dataList) {
    this.item_layout = item_gridview;
    this.mDataList = dataList;
    mInts = Arrays.asList(R.mipmap.ic_launcher, R.mipmap.ic_launcher,
        R.mipmap.ic_launcher, R.mipmap.ic_launcher,
        R.mipmap.ic_launcher, R.mipmap.ic_launcher);
  }
  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(item_layout, parent, false);
    return new ViewHolder(view);
  }
  @Override
  public void onBindViewHolder(ViewHolder holder, int position) {
    String str = mDataList.get(position);
    if (isFirstSpecial && position == 0) {
      holder.itemView.setBackgroundColor(Color.LTGRAY);
      holder.mTextView.setText("不许动");
      holder.mImageView.setImageResource(R.mipmap.ic_launcher);
    } else {
      holder.itemView.setBackgroundColor(Color.WHITE);
      holder.mTextView.setText(str);
      holder.mImageView.setImageResource(mInts.get(position % mInts.size()));
    }
  }
  @Override
  public int getItemCount() {
    return mDataList == null ? 0 : mDataList.size();
  }
  public List<String> getDataList() {
    return mDataList;
  }
  class ViewHolder extends RecyclerView.ViewHolder {
    TextView mTextView;
    ImageView mImageView;
    public ViewHolder(View itemView) {
      super(itemView);
      mTextView = itemView.findViewById(R.id.tv_item);
      mImageView = itemView.findViewById(R.id.img_item);
    }
  }
}

OnRecyclerItemClickListener,点击事件 。我们借用手势工具类GestureDetectorCompat 来操作

public abstract class OnRecyclerItemClickListener implements RecyclerView.OnItemTouchListener{
  private GestureDetectorCompat mGestureDetectorCompat;
  private RecyclerView mRecyclerView;
  public OnRecyclerItemClickListener(RecyclerView mRecyclerView) {
    this.mRecyclerView = mRecyclerView;
    mGestureDetectorCompat = new GestureDetectorCompat(mRecyclerView.getContext(),
        new ItemTouchHelperGestureListener());
  }
  @Override
  public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
    mGestureDetectorCompat.onTouchEvent(e);
    return false;
  }
  @Override
  public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    mGestureDetectorCompat.onTouchEvent(e);
  }
  @Override
  public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
  }
  //回调事件
  public abstract void onItemClick(RecyclerView.ViewHolder viewHolder);
  public abstract void onLongClick(RecyclerView.ViewHolder viewHolder);
  private class ItemTouchHelperGestureListener extends GestureDetector.SimpleOnGestureListener {
    @Override
    public boolean onSingleTapUp(MotionEvent e) {
      View childViewUnder = mRecyclerView.findChildViewUnder(e.getX(), e.getY());
      if (childViewUnder != null) {
        RecyclerView.ViewHolder childViewHolder = mRecyclerView.getChildViewHolder(childViewUnder);
        onItemClick(childViewHolder);
      }
      return true;
    }
    @Override
    public void onLongPress(MotionEvent e) {
      View childViewUnder = mRecyclerView.findChildViewUnder(e.getX(), e.getY());
      if (childViewUnder != null) {
        RecyclerView.ViewHolder childViewHolder = mRecyclerView.getChildViewHolder(childViewUnder);
        onLongClick(childViewHolder);
      }
    }
  }
}

RecyItemTouchHelperCallback

public class RecyItemTouchHelperCallback extends ItemTouchHelper.Callback {
  RecyclerView.Adapter mAdapter;
  boolean isSwipeEnable;
  boolean isFirstDragUnable;
  public RecyItemTouchHelperCallback(RecyclerView.Adapter mAdapter) {
    this.mAdapter = mAdapter;
    isSwipeEnable = true;
    isFirstDragUnable = false;
  }
  public RecyItemTouchHelperCallback(RecyclerView.Adapter mAdapter, boolean isSwipeEnable, boolean isFirstDragUnable) {
    this.mAdapter = mAdapter;
    this.isSwipeEnable = isSwipeEnable;
    this.isFirstDragUnable = isFirstDragUnable;
  }
//  获取Touch的响应方向
  @Override
  public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {//网格布局时候
      int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN |
          ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
      int swipeFlags = 0;
      return makeMovementFlags(dragFlags, swipeFlags);
    } else {//list布局时候
      int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
      int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
      return makeMovementFlags(dragFlags, swipeFlags);
    }
  }
  @Override
  public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
    int fromPosition = viewHolder.getAdapterPosition();
    int toPosition = target.getAdapterPosition();
    if (isFirstDragUnable && toPosition == 0) {
      return false;
    }
    //重新更新排序
    if (fromPosition < toPosition) {
      for (int i = fromPosition; i < toPosition; i++) {
        Collections.swap(((RecyclerAdapter) mAdapter).getDataList(), i, i + 1);
      }
    } else {
      for (int i = fromPosition; i > toPosition; i--) {
        Collections.swap(((RecyclerAdapter) mAdapter).getDataList(), i, i - 1);
      }
    }
    //刷新
    mAdapter.notifyItemMoved(fromPosition, toPosition);
    return true;
  }
  /**
   * 侧滑删除后会回调的方法
   */
  @Override
  public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
    int adapterPosition = viewHolder.getAdapterPosition();
    mAdapter.notifyItemRemoved(adapterPosition);
    ((RecyclerAdapter)mAdapter).getDataList().remove(adapterPosition);
  }
  @Override
  public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
      viewHolder.itemView.setBackgroundColor(Color.LTGRAY);
    }
    super.onSelectedChanged(viewHolder, actionState);
  }
  @Override
  public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    super.clearView(recyclerView, viewHolder);
    viewHolder.itemView.setBackgroundColor(Color.WHITE);
  }
  @Override
  public boolean isLongPressDragEnabled() {
    return !isFirstDragUnable;
  }
  @Override
  public boolean isItemViewSwipeEnabled() {
    return isSwipeEnable;
  }
}

下面是list的相关设置

同样,listview也是一顿初始化设置。

public class ListViewActivity extends AppCompatActivity {
  RecyclerView mRecyclerView;
  List<String> mStringList;
  RecyclerAdapter mRecyAdapter;
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recyclerview);
    initView();
    initRecy();
  }
  private void initRecy() {
    if (mStringList == null) {
      mStringList = new ArrayList<>();
    }
    mStringList.addAll(DataManager.getData(15 - mStringList.size()));
    mRecyAdapter = new RecyclerAdapter(R.layout.item_listview, mStringList);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.addItemDecoration(new DividerListItemDecoration(this, LinearLayoutManager.VERTICAL));
    mRecyclerView.setHasFixedSize(true);
    RecyItemTouchHelperCallback itemTouchHelperCallback = new RecyItemTouchHelperCallback(mRecyAdapter);
    final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback);
    itemTouchHelper.attachToRecyclerView(mRecyclerView);
    mRecyclerView.addOnItemTouchListener(new OnRecyclerItemClickListener(mRecyclerView) {
      @Override
      public void onItemClick(RecyclerView.ViewHolder viewHolder) {
        RecyclerAdapter.ViewHolder viewHolder1 = (RecyclerAdapter.ViewHolder) viewHolder;
        String tvString = viewHolder1.mTextView.getText().toString();
        Toast.makeText(ListViewActivity.this, "碰了一下 " + tvString, Toast.LENGTH_SHORT).show();
      }
      @Override
      public void onLongClick(RecyclerView.ViewHolder viewHolder) {
        Toast.makeText(ListViewActivity.this, "长按不放可以拖动!", Toast.LENGTH_SHORT).show();
      }
    });
    mRecyclerView.setAdapter(mRecyAdapter);
  }
  private void initView() {
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mRecyclerView = (RecyclerView) findViewById(R.id.view_recycler);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
      finish();
    }
    return super.onOptionsItemSelected(item);
  }
}

DividerListItemDecoration

public class DividerListItemDecoration extends RecyclerView.ItemDecoration {
  private static final int[] ATTRS = new int[] {android.R.attr.listDivider};
  public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
  public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
  private Drawable mDivider;
  private int mOrientation;
  public DividerListItemDecoration() {
    super();
  }
  public DividerListItemDecoration(Context context, int orientation) {
    final TypedArray array = context.obtainStyledAttributes(ATTRS);
    mDivider = array.getDrawable(0);
    array.recycle();
    this.mOrientation = orientation;
  }
  public DividerListItemDecoration(Context context, int orientation, int drawableId) {
    mDivider = ContextCompat.getDrawable(context, drawableId);
    setOrientation(orientation);
  }
  @Override
  public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDraw(c, parent, state);
  }
  @Override
  public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDrawOver(c, parent, state);
  }
  @Override
  public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if (mOrientation == VERTICAL_LIST) {
      outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
    } else {
      outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
    }
    super.getItemOffsets(outRect, view, parent, state);
  }
  public void setOrientation(int orientation) {
    if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) {
      throw new IllegalArgumentException("invalid orientaion");
    }
    mOrientation = orientation;
  }
}

源码下载:http://download.csdn.net/download/loongago/9972876

总结

以上所述是小编给大家介绍的Android中RecyclerView拖拽、侧删功能的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!

(0)

相关推荐

  • Android RecyclerView 实现快速滚动的示例代码

    简评:Android Support Library 26 中终于实现了一个等待已久的功能: RecyclerView 的快速滚动 . Android 官方早就在建议开发者使用 RecyclerView 替代 ListView,RecyclerView 也确实表现要好于 ListView,除了没有快速滚动,就像下面这样: 因此,之前要想在 RecyclerView 上实现快速滚动,往往是依赖第三方库,比如:FutureMind/recycler-fast-scroll或 timusus/Recy

  • Android 中RecyclerView顶部刷新实现详解

    Android 中RecyclerView顶部刷新实现详解 1. RecyclerView顶部刷新的原理 RecyclerView顶部刷新的实现通常都是在RecyclerView外部再包裹一层布局.在这个外层布局中,还包含一个自定义的View,作为顶部刷新时的指示View.也就是说,外层布局中包含两个child,一个顶部刷新View,一个RecyclerView,顶部刷新View默认是隐藏不可见的.在外层布局中对滑动事件进行处理,当RecyclerView滑动到顶部并继续下滑的时候,根据滑动的距

  • Android用RecyclerView实现动态添加本地图片

    本文介绍了Android用RecyclerView实现动态添加本地图片,分享给大家,具体如下: 本文所用的多图选择的library来自:https://github.com/lovetuzitong/MultiImageSelector 简单介绍一下用法: 1.跳转到图片选择页面: Intent intent = new Intent(PassengerSetActivity.this, MultiImageSelectorActivity.class); intent.putExtra(Mul

  • Android RecyclerView设置下拉刷新的实现方法

    Android RecyclerView设置下拉刷新的实现方法 1 集成 SwipeRefreshLayout 1.1 xml布局文件中使用 <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/refresh" android:layout_width = "match_parent" android:layout_height = "match_parent" &g

  • Android中RecyclerView实现Item添加和删除的代码示例

    本文介绍了Android中RecyclerView实现Item添加和删除的代码示例,分享给大家,具体如下: 先上效果图: RecyclerView简介: RecyclerView用以下两种方式简化了数据的展示和处理: 1. 使用LayoutManager来确定每一个item的排列方式. 2. 为增加和删除项目提供默认的动画效果,也可以自定义. RecyclerView项目结构如下: Adapter:使用RecyclerView之前,你需要一个继承自RecyclerView.Adapter的适配器

  • Android ExpandableRecyclerView使用方法详解

    本文为大家分享了Android ExpandableRecyclerView的使用,供大家参考,具体内容如下 1.目前只支持两级结构. 2.支持所有组同时全部展开,支持同一时间只能展开一组. 3.GroupView,ChildView高度自定义. 4.支持初始化数据时,指定展开某组数据. 5.支持GroupItem,ChildItem的Onlick,OnLongClick事件. 6.展开收起带动画. 效果图: 使用步骤:加入依赖 compile 'com.drawthink:expandable

  • Android中RecyclerView拖拽、侧删功能的实现代码

    废话不多说,下面展示一下效果. 这是GridView主文件实现. public class GridViewActivity extends AppCompatActivity { RecyclerView mRecyclerView; List<String> mStringList; RecyclerAdapter mRecyAdapter; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { s

  • Android中 TeaScreenPopupWindow多类型筛选弹框功能的实例代码

    Github地址 YangsBryant/TeaScreenPopupWindow (Github排版比较好,建议进入这里查看详情,如果觉得好,点个star吧!) 引入module allprojects { repositories { google() jcenter() maven { url 'https://www.jitpack.io' } } } implementation 'com.github.YangsBryant:TeaScreenPopupWindow:1.0.2' 主

  • 使用konva和vue-konva库实现拖拽滑块验证功能

    1. 在vue项目中安装konva和vue-konva库 npm install konva vue-konva --save-dev 2. 引入vue-konva库 import VueKonva from 'vue-konva': Vue.use(VueKonva) 3. 创建单独的滑块验证组件 Captcha.vue,在相应的页面中引入使用即可 <template> <v-stage :config="Config.stage"> <v-layer

  • vue实现指定区域自由拖拽、打印功能

    本文实例为大家分享了vue实现指定区域自由拖拽.打印功能的具体代码,供大家参考,具体内容如下 先看下效果图,实现指定区域内内容自由拖拽,不超出.动态设置字体颜色及字号:设置完成实现打印指定区域内容,样式不丢失. 1.运行命令npm i vue-draggable-resizable -S, 安装拖拽插件vue-draggable-resizable,并引入使用(下面引入是放入main.js文件中) import VueDraggableResizable from 'vue-draggable-

  • 基于jquery插件实现拖拽删除图片功能

    本文实例为大家分享了jquery插件实现拖拽删除图片功能的具体代码,供大家参考,具体内容如下 实现以下效果 完全拖出这个层,图片会消失,否则图片会回到原来的位置 <html> <head> <title></title> <style type="text/css"> #mydiv{ width:900px; background-color:#444; border:1px solid red} #mydiv2{ width

  • Android 仿微信发动态九宫格拖拽、删除功能

    1.完美1比1 仿照微信仿微信发动态 九宫格拖拽.删除 暴力拖拽ui有点问题,不影响使用,资源文件自己找个+号 2.微信发动态拖拽bug 当选择完图片,长按图片拖拽过程中按下屏幕home键盘,再次进入这时候就不能点击输入文字,点击输入文字的时候会触发选择相册事件 3.拖拽事件用的basequickadapter implementation 'com.android.support:recyclerview-v7:28.0.0' implementation "com.github.CymCha

  • Android TouchListener实现拖拽删实例代码

    Android TouchListener实现拖拽删实例代码 如果为一个控件设置了该触摸监听, 控件会随着用户的拖动而移动, 如果拖动的距离大过设置的临界值, 那么当松开手指时会有回调onDragComplete, 用户可在该方法中将该控件从父布局中删除, 或这进行其他操作. 如果用户拖拽的距离小于临界值, 那么当用户松开手指时控件会回谈到原来的初始位置.这时会触发onDragRebound回调. 如果用户触摸控件之后没有拖拽而是直接松开手指, 会触发onClick回调, 这样用户就不用为该控件

  • Android实现可拖拽列表和多选功能

    本文实例为大家分享了Android实现可拖拽列表和多选的具体代码,供大家参考,具体内容如下 这是我已经完成的一个已经上线的OA软件的一个模块,这个模块的功能不多,已经放到GitHub上面开源了,有感兴趣的朋友可以看看UIFrame 主窗口JAVA代码 /** * 编辑状态下长按拖动条目 * 1.通过ItemTouchHelper.Callback实现长按拖动 * 2.通过isEditable的值判断是否编辑状态,初值是false * 3.切换编辑状态要把isEditable的值取反,并改变复选框

  • java swing中实现拖拽功能示例

    java实现拖拽示例 Swing中实现拖拽功能,代码很简单,都有注释,自己看,运行效果如下图: 复制代码 代码如下: package com; import java.awt.*;import java.awt.datatransfer.DataFlavor;import java.awt.dnd.DnDConstants;import java.awt.dnd.DropTarget;import java.awt.dnd.DropTargetAdapter;import java.awt.dn

  • Android实现按钮拖拽还原功能

    具体代码如下所示: public class MainActivity extends AppCompatActivity { private ImageButton ibOk ; private int lastX; private int lastY; private int startLeft; private int startRight; private int startTop; private int startBottom; @Override protected void on

随机推荐