Android 上拉滑动上滑拖出pop 类似百度地图抽屉拖拽效果

 

这里我们用到GitHub上个一个开源库:https://github.com/yingLanNull/ScrollLayout

先看效果图

 

大概就是这样的一个效果,这个库功能非常多,感谢前辈们的贡献!

--------------------------------------手动分割----------------------------------------------------------------.

首先添加依赖

 

compile 'com.yinglan.scrolllayout:scrolllayout:1.0.2'

开始写布局,我这个布局就一个Button其他的都是这个控件所需要的

activity.xml

 
  1. <RelativeLayout

  2. xmlns:android="http://schemas.android.com/apk/res/android"

  3. xmlns:tools="http://schemas.android.com/tools"

  4. android:id="@+id/root"

  5. android:layout_width="match_parent"

  6. android:layout_height="match_parent"

  7. tools:context=".MainActivity">

  8.  
  9. <com.yinglan.scrolllayout.ScrollLayout

  10. android:id="@+id/scroll_down_layout"

  11. android:layout_width="match_parent"

  12. android:layout_height="match_parent"

  13. android:background="#000000"

  14. >

  15.  
  16.  
  17. <RelativeLayout

  18. android:layout_width="match_parent"

  19. android:layout_height="match_parent">

  20.  
  21. <com.yinglan.scrolllayout.content.ContentListView

  22. android:id="@+id/list_view"

  23. android:layout_width="match_parent"

  24. android:layout_height="match_parent"

  25. android:background="@android:color/white"

  26. ></com.yinglan.scrolllayout.content.ContentListView>

  27.  
  28. <TextView

  29. android:id="@+id/text_foot"

  30. android:layout_width="match_parent"

  31. android:layout_height="50dp"

  32. android:background="@color/colorPrimaryDark"

  33. android:clickable="true"

  34. android:gravity="center"

  35. android:text="点击或上滑打开" />

  36. </RelativeLayout>

  37. </com.yinglan.scrolllayout.ScrollLayout>

  38.  
  39. <Button

  40. android:id="@+id/test_bt"

  41. android:layout_width="wrap_content"

  42. android:layout_height="wrap_content"

  43. android:text="测试按钮"

  44. />

  45.  
  46. </RelativeLayout>

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
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 上下滑动抽屉的基本步骤。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值