day45 SwipeLayout简单使用

依赖:implementation “com.daimajia.swipelayout:library:1.2.0@aar”

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.daimajia.swipe.SwipeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:id="@+id/swipe">
        <LinearLayout
            android:tag="right"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="right"
            android:orientation="vertical">
            <Button
                android:layout_gravity="right"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/delBtn"
                android:text="删除"/>
        </LinearLayout>

        <LinearLayout android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="#000ff0">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="一条显示内容" />
        </LinearLayout>

    </com.daimajia.swipe.SwipeLayout>

</LinearLayout>
public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private SwipeLayout swipeLayout;
    private Button mBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化基本控件
        swipeLayout = findViewById(R.id.swipe);
        mBtn = findViewById(R.id.delBtn);
        mBtn.setOnClickListener(this);
        //设置滑动布局
        swipeLayout.addDrag(SwipeLayout.DragEdge.Right,swipeLayout.findViewWithTag("right"));
        //设置滑动模式laydown->在顶部布局下;pullout->在顶部布局的右侧
        swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
        swipeLayout.getSurfaceView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this,"顶部被点击",Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void onClick(View v) {
        swipeLayout.close();
        Toast.makeText(this,"删除按钮被点击",Toast.LENGTH_SHORT).show();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值