android-swipelistview使用说明
项目地址:https://github.com/47deg/android-swipelistview参数说明:http://www.jcodecraeer.com/a/opensource/2014/1015/1777.html代码来源:http://www.apkbus.com/android-143803-1-1.html效果图<com.for
项目地址:https://github.com/47deg/android-swipelistview
参数说明:http://www.jcodecraeer.com/a/opensource/2014/1015/1777.html
代码来源:http://www.apkbus.com/android-143803-1-1.html
效果图
<com.fortysevendeg.swipelistview.SwipeListView
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="@+id/example_lv_list"
android:listSelector="#00000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
swipe:swipeFrontView="@+id/front"
swipe:swipeBackView="@+id/back"
swipe:swipeActionLeft="[reveal | dismiss]"
swipe:swipeActionRight="[reveal | dismiss]"
swipe:swipeMode="[none | both | right | left]"
swipe:swipeCloseAllItemsWhenMoveList="[true | false]"
swipe:swipeOpenOnLongPress="[true | false]"
swipe:swipeAnimationTime="[miliseconds]"
swipe:swipeOffsetLeft="[dimension]"
swipe:swipeOffsetRight="[dimension]"
/>
swipeFrontView
- Required - front view id.swipeBackView
- Required - back view id.swipeActionLeft
- Optional - left swipe action Default: 'reveal'swipeActionRight
- Optional - right swipe action Default: 'reveal'swipeMode
- Gestures to enable or 'none'. Default: 'both'swipeCloseAllItemsWhenMoveList
- Close revealed items on list motion. Default: 'true'swipeOpenOnLongPress
- Reveal on long press Default: 'true'swipeAnimationTime
- item drop animation time. Default: android configurationswipeOffsetLeft
- left offsetswipeOffsetRight
- right offset
中文:
-
swipeFrontView
- Required - front view id. 即ListView Item正常显示的控件Id,且必须与Item的布局文件中的控件id一样 -
swipeBackView
- Required - back view id. 手指滑动时显示的,隐藏在FrontView后面,且必须与item的布局文件中控件Id一样 -
swipeActionLeft
- Optional - left swipe action Default: 'reveal' 左滑的动作,默认reveal,即显示BackView,还有dismiss,choice会触发响应的方法。 -
swipeActionRight
- Optional - right swipe action Default: 'reveal' 同上 -
swipeMode
- Gestures to enable or 'none'. Default: 'both' 设置左滑、右滑、都支持 -
swipeCloseAllItemsWhenMoveList
- Close revealed items on list motion. Default: 'true' 当滚动listview时,关闭所有展开的Item,最好不要设置为false,由于item的复用,false存在一些问题。 -
swipeOpenOnLongPress
- Reveal on long press Default: 'true' 长按时触发显示 -
swipeAnimationTime
- item drop animation time. Default: android configuration 动画时间长度 -
swipeOffsetLeft
- left offset 左偏移量 -
swipeOffsetRight
- right offset 右偏移量
MainActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import com.fortysevendeg.swipelistview.BaseSwipeListViewListener;
import com.fortysevendeg.swipelistview.SwipeListView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MainActivity extends Activity {
private SwipeListView mSwipeListView ;
private SwipeAdapter mAdapter ;
public static int deviceWidth ;
private List<String> testData ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSwipeListView = (SwipeListView) findViewById(R.id.example_lv_list);
testData = getTestData();
mAdapter = new SwipeAdapter(this, R.layout.package_row, testData,mSwipeListView);
deviceWidth = getDeviceWidth();
mSwipeListView.setAdapter(mAdapter);
mSwipeListView.setSwipeListViewListener( new TestBaseSwipeListViewListener());
reload();
}
private List<String> getTestData() {
String [] obj = new String[]{"图震APP","看美女","看汽车","下载地址","小米市场","豌豆荚市场","每天更新","你要的不是我","不潮不用花钱","只对你有感觉","简简单单"};
List<String> list = new ArrayList<String>(Arrays.asList(obj));
return list;
}
private int getDeviceWidth() {
return getResources().getDisplayMetrics().widthPixels;
}
private void reload() {
mSwipeListView.setSwipeMode(SwipeListView.SWIPE_MODE_LEFT);
mSwipeListView.setSwipeActionLeft(SwipeListView.SWIPE_ACTION_REVEAL);
// mSwipeListView.setSwipeActionRight(settings.getSwipeActionRight());
mSwipeListView.setOffsetLeft(deviceWidth * 1 / 3);
// mSwipeListView.setOffsetRight(convertDpToPixel(settings.getSwipeOffsetRight()));
mSwipeListView.setAnimationTime(0);
mSwipeListView.setSwipeOpenOnLongPress(false);
}
class TestBaseSwipeListViewListener extends BaseSwipeListViewListener{
@Override
public void onClickFrontView(int position) {
super.onClickFrontView(position);
Toast.makeText(getApplicationContext(), testData.get(position), Toast.LENGTH_SHORT).show();
}
@Override
public void onDismiss(int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
testData.remove(position);
}
mAdapter.notifyDataSetChanged();
}
}
}
SwipeAdapter.java
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import com.fortysevendeg.swipelistview.SwipeListView;
import java.util.List;
public class SwipeAdapter extends ArrayAdapter<String> {
private LayoutInflater mInflater ;
private List<String> objects ;
private SwipeListView mSwipeListView ;
public SwipeAdapter(Context context, int textViewResourceId,List<String> objects, SwipeListView mSwipeListView) {
super(context, textViewResourceId, objects);
this.objects = objects ;
this.mSwipeListView = mSwipeListView ;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder = null ;
if(convertView == null){
convertView = mInflater.inflate(R.layout.package_row, parent, false);
holder = new ViewHolder();
holder.mFrontText = (TextView) convertView.findViewById(R.id.example_row_tv_title);
holder.mBackEdit = (Button) convertView.findViewById(R.id.example_row_b_action_3);
holder.mBackDelete = (Button) convertView.findViewById(R.id.example_row_b_action_2);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.mBackDelete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mSwipeListView.closeAnimate(position);
mSwipeListView.dismiss(position);
}
});
String item = getItem(position);
holder.mFrontText.setText(item);
return convertView;
}
class ViewHolder{
TextView mFrontText ;
Button mBackEdit,mBackDelete ;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<com.fortysevendeg.swipelistview.SwipeListView
android:id="@+id/example_lv_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:listSelector="#00000000"
swipe:swipeActionLeft="reveal"
swipe:swipeActionRight="reveal"
swipe:swipeAnimationTime="0"
swipe:swipeBackView="@+id/back"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeFrontView="@+id/front"
swipe:swipeMode="both"
swipe:swipeOffsetLeft="0dp"
swipe:swipeOffsetRight="0dp"
swipe:swipeOpenOnLongPress="false" />
</RelativeLayout>
package_row.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/back"
android:layout_width="match_parent"
android:layout_height="80dp"
android:tag="back"
android:background="#eee"
>
<Button
android:id="@+id/example_row_b_action_1"
android:layout_width="0dp"
android:background="@null"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="@+id/example_row_b_action_2"
android:layout_width="0dp"
android:layout_marginLeft="10dp"
android:layout_height="60dp"
android:text="删除"
android:layout_gravity="center"
android:layout_weight="1" />
<Button
android:id="@+id/example_row_b_action_3"
android:layout_width="0dp"
android:text="编辑"
android:layout_gravity="center"
android:layout_height="60dp"
android:layout_weight="1" />
</LinearLayout>
<RelativeLayout
android:id="@+id/front"
android:orientation="vertical"
android:tag="front"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="80dp" >
<TextView
android:id="@+id/example_row_tv_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="18sp"
/>
</RelativeLayout>
</FrameLayout>
下载地址 http://download.csdn.net/detail/wyyl1/9077749
更多推荐
所有评论(0)