Android SwipeDrawer 滑动抽屉库

Android SwipeDrawer滑动抽屉库,可同时添加上下左右四个方向抽屉布局,打开模式有抽屉模式、覆盖模式、固定模式三种,支持无限嵌套,支持边缘滑动打开等,SwipeDrawer还可以当做下拉刷新布局使用,支持ListView、RecyclerView、GridView、ScrollView等。

开始使用

添加 jitpack 仓库地址:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

添加 SwipeDrawer 依赖:

dependencies {
    ...
    implementation 'cn.Leaqi:SwipeDrawer:1.0'
}

在布局文件中加入 SwipeDrawer

<cn.leaqi.drawer.SwipeDrawer
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:leftLayout="@+id/leftDrawer">

    <!-- leftLayout属性指定Left布局 -->
    <LinearLayout
        android:id="@+id/leftDrawer"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:background="#FF5722">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Left" />
    </LinearLayout>

    <!-- 默认第一个未指定ID的布局为主布局 -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Main" />
    </RelativeLayout>
</cn.leaqi.drawer.SwipeDrawer>

图片预览 · 查看更多

Demo Demo
Demo Demo

Github

https://github.com/Leaqi/SwipeDrawer

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 中,可以使用 NavigationDrawer 实现上下滑动抽屉效果。以下是一些步骤: 1. 在布局文件中添加 DrawerLayout 和 NavigationView。 ```xml <androidx.drawerlayout.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 主要内容 --> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- 抽屉 --> <com.google.android.material.navigation.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:menu="@menu/menu_drawer" /> </androidx.drawerlayout.widget.DrawerLayout> ``` 2. 在 Activity 中设置 DrawerLayout,并设置 ActionBar。 ```java private ActionBarDrawerToggle toggle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 设置 ActionBar setSupportActionBar(findViewById(R.id.toolbar)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); DrawerLayout drawer = findViewById(R.id.drawer_layout); // 设置抽屉的开关 toggle = new ActionBarDrawerToggle( this, drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); // 设置 NavigationView 的点击事件 NavigationView navigationView = findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); } // 处理 ActionBar 的点击事件 @Override public boolean onOptionsItemSelected(MenuItem item) { if (toggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); } ``` 3. 在 res/menu 文件夹下创建 menu_drawer.xml 文件用于设置 NavigationView 的菜单项。 ```xml <menu xmlns:android="http://schemas.android.com/apk/res/android"> <group android:checkableBehavior="single"> <item android:id="@+id/nav_home" android:icon="@drawable/ic_home" android:title="Home" /> <item android:id="@+id/nav_gallery" android:icon="@drawable/ic_gallery" android:title="Gallery" /> <item android:id="@+id/nav_slideshow" android:icon="@drawable/ic_slideshow" android:title="Slideshow" /> </group> </menu> ``` 4. 处理 NavigationView 的点击事件。 ```java @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { int id = item.getItemId(); if (id == R.id.nav_home) { // 处理菜单项的点击事件 } else if (id == R.id.nav_gallery) { // 处理菜单项的点击事件 } else if (id == R.id.nav_slideshow) { // 处理菜单项的点击事件 } DrawerLayout drawer = findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } ``` 以上就是实现 Android 上下滑动抽屉的基本步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值