DragLinearLayout-使子View可拖动的LinearLayout.zip
DragLinearLayout是一个LinearLayout, 他可是其子View在其范围内可拖动、可交换位置。默认情况下,子View是不可拖动的,你需要调用DragLinearLayout.setViewDraggable(child, child)方法让其可拖动。项目地址:https://github.com/justasm/DragLinearLayout 效果图:如何使用和使用LinearLayout一样:<com.jmedeisis.draglinearlayout.DragLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@ id/container" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/text" /> <ImageView android:layout_width="match_parent" android:layout_height="120dp" android:scaleType="centerCrop" android:src="@drawable/image"/> <Button android:id="@ id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button_text"/> </com.jmedeisis.draglinearlayout.DragLinearLayout>2. 让子View可拖动默认情况下子View是不可拖动的,你需要调用dragLinearLayout.setViewDraggable()让子View变为可拖动的。DragLinearLayout dragLinearLayout = (DragLinearLayout) findViewById(R.id.container); //让子view可拖动,默认是不能拖动的 for(int i = 1; i < dragLinearLayout.getChildCount(); i ){ View child = dragLinearLayout.getChildAt(i); dragLinearLayout.setViewDraggable(child, child); }可以动态添加可拖动子viewfinal View view = View.inflate(context, R.layout.view_layout, null); dragLinearLayout.addDragView(view, view.findViewById(R.id.view_drag_handle)); // .. dragLinearLayout.removeDragView(view);使用OnViewSwapListener检测子view之间的排序变化事件:dragLinearLayout.setOnViewSwapListener(new DragLinearLayout.OnViewSwapListener() { @Override public void onSwap(View firstView, int firstPosition, View secondView, int secondPosition) { // update data, etc.. } });当在ScrollView中使用DragLinearLayout的时候,如果你想在拖拽的时候ScrollView也能滚动,需要调用setContainerScrollView(ScrollView)为了达到最佳效果,最好给子view加上不透明的背景色。不要给DragLinearLayout设置padding,如果需要padding,加在子view上。
- 1
- 粉丝: 327
- 资源: 2万+
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助