AndroidSwipeLayout理解

燕俊明
2023-12-01

1.AndroidSwipeLayout见 https://github.com/daimajia/AndroidSwipeLayout/wiki/usage

2.使用方式跟DrawerLayout类似。结合listview可以实现QQ聊天列表左滑删除效果

3.代码示例

@ContentView(R.layout.activity_main)
public class MainActivity extends AppCompatActivity implements View.OnClickListener{

//    @ViewInject(R.id.save)
//    Button btn;
//    @ViewInject(R.id.scalpel)
//    ScalpelFrameLayout scalpelView;
//    @ViewInject(R.id.bottom_wrapper)
//    LinearLayout b;
//    @ViewInject(R.id.surface)
//    LinearLayout s;
    @ViewInject(R.id.list_view)
    ListView listView;
    MyListAdapter adapter;
    ArrayList<String> lists;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        lists = new ArrayList<>();
        for(int i = 1 ;i<= 10 ;i++){
            lists.add("Item"+i);
        }
        adapter = new MyListAdapter(lists,getLayoutInflater());
        listView.setAdapter(adapter);
    }

@Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHoler holer = null;
        if(view == null){
            view = inflater.inflate(R.layout.item_list_view,viewGroup,false);
            holer = new ViewHoler(view);
            view.setTag(holer);
        }
        holer = (ViewHoler) view.getTag();
        holer.b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("------------------", String.valueOf(i));
            }
        });
        holer.s.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("------------------", String.valueOf(i));
            }
        });
        holer.t.setText(lists.get(i));

        holer.swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);

        holer.swipeLayout.addDrag(SwipeLayout.DragEdge.Left, holer.b);
        return view;
    }
    static class ViewHoler{
        LinearLayout s,b;
        TextView t;
        SwipeLayout swipeLayout;
        ViewHoler(View v){
            s = (LinearLayout) v.findViewById(R.id.surface);
            b = (LinearLayout) v.findViewById(R.id.bottom_wrapper);
            t = (TextView) v.findViewById(R.id.txt);
            swipeLayout = (SwipeLayout) v.findViewById(R.id.sample1);
        }
    }


 类似资料: