Android BottomSheet:List列表或Grid网格展示(3)

BottomSheet可以显示多种样式的底部弹出面板风格,比如常见的List列表样式或者Grid网格样式,以一个例子说明。

先写一个布局,该布局作为Activity的布局加载,BottomSheet将从此Activity的底部弹出弹入。布局中只有两个button按钮,分别触发List或者Grid面板:

<?xml version="1.0" encoding="utf-8"?>
<com.flipboard.bottomsheet.BottomSheetLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottomsheet"
android:layout_width="match_parent"
android:layout_height="match_parent"> <LinearLayout
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:orientation="vertical"
android:padding="16dp"> <Button
android:id="@+id/list_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/list_button" /> <Button
android:id="@+id/grid_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/grid_button" /> </LinearLayout> </com.flipboard.bottomsheet.BottomSheetLayout>

上层Java代码:

package com.flipboard.bottomsheet.sample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast; import com.flipboard.bottomsheet.BottomSheetLayout;
import com.flipboard.bottomsheet.R;
import com.flipboard.bottomsheet.commons.MenuSheetView; /**
* Activity demonstrating the use of {@link MenuSheetView}
*/
public class MenuActivity extends AppCompatActivity { protected BottomSheetLayout bottomSheetLayout; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
bottomSheetLayout = (BottomSheetLayout) findViewById(R.id.bottomsheet);
bottomSheetLayout.setPeekOnDismiss(true);
findViewById(R.id.list_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//显示列表样式菜单
//传入一个MenuSheetView.MenuType.LIST的值,标明弹出面板样式
showMenuSheet(MenuSheetView.MenuType.LIST);
}
});
findViewById(R.id.grid_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//弹出网格样式的面板
showMenuSheet(MenuSheetView.MenuType.GRID);
}
});
} private void showMenuSheet(final MenuSheetView.MenuType menuType) {
MenuSheetView menuSheetView =
new MenuSheetView(MenuActivity.this, menuType, "请选择...", new MenuSheetView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(MenuActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show(); //因为点击了面板中的某一项,关闭这个面板
if (bottomSheetLayout.isSheetShowing()) {
bottomSheetLayout.dismissSheet();
} //假设用户选择以另外一种方式打开
//则重新切换样式
if (item.getItemId() == R.id.reopen) {
showMenuSheet(menuType == MenuSheetView.MenuType.LIST ? MenuSheetView.MenuType.GRID : MenuSheetView.MenuType.LIST);
} return true;
}
}); //此处构造展示出来的面板选项条目的数据源
//从menu菜单的数据创建
//类似适配器
menuSheetView.inflateMenu(R.menu.create); //不要忘记这段代码,否则显示不出来
bottomSheetLayout.showWithSheetView(menuSheetView);
}
}

BottomSheet的数据源是从res/menu/下给出的菜单数据构造item。本例中用到的res/menu/create.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:icon="@mipmap/ic_launcher"
android:title="@string/document" />
<item
android:icon="@mipmap/ic_launcher"
android:title="@string/spreadsheet" />
<item
android:icon="@mipmap/ic_launcher"
android:title="@string/folder" /> <item
android:id="@+id/menu_subheader"
android:title="子菜单">
<menu>
<item
android:id="@+id/navigation_sub_item_1"
android:icon="@mipmap/ic_launcher"
android:title="@string/upload_photos" />
<item
android:id="@+id/navigation_sub_item_2"
android:icon="@mipmap/ic_launcher"
android:title="@string/use_camera" />
</menu>
</item>
<item
android:id="@+id/reopen"
android:icon="@mipmap/ic_launcher"
android:title="@string/reopen" /> </menu>

代码运行结果->

List:

Grid:

附录文章:

1,《Android自底部平滑向上滑出面板的AndroidSlidingUpPanel》链接地址:http://blog.csdn.net/zhangphil/article/details/51444509


2,《Android音乐、视频类APP常用控件:DraggablePanel(1)》链接地址:http://blog.csdn.net/zhangphil/article/details/51566860 


3,《Android音乐、视频类APP常用控件:DraggablePanel(2)》链接地址:http://blog.csdn.net/zhangphil/article/details/51578665

4,《Android图片加载与缓存开源框架:Android Glide》链接地址http://blog.csdn.net/zhangphil/article/details/45535693

5,《Android BottomSheet:便捷易用的底部滑出面板(1)》链接地址:http://blog.csdn.net/zhangphil/article/details/51775955

6,《Android BottomSheet:以选取图片为例(2)》链接地址:http://blog.csdn.net/zhangphil/article/details/51776408

Android BottomSheet:List列表或Grid网格展示(3)的更多相关文章

  1. Android BottomSheet:底部弹出Fragment面板(4)

     Android BottomSheet:底部弹出Fragment面板(4) BottomSheet不仅可以弹出轻量级的定制好的面板(见附录文章5,6,7),还可以弹出"重"的 ...

  2. grid网格布局使用

    定义 grid布局是指对网页进行划分成一个一个网格,然后根据自己的要求,可以任意组合. 以前写类似的功能,很麻烦,需要写很多的CSS去控制,有了grid就很方便了,可以随意进行组合. 跟flex有很多 ...

  3. fir.im Weekly - 2016 年 Android 最佳实践列表

    2016 年已经过去一半,你在年初制定的成长计划都实现了吗? 学海无涯,技术成长不是一簇而就的事情.本期 fir.im Weekly 推荐 王下邀月熊_Chevalier的 我的编程之路--知识管理与 ...

  4. Android一个ListView列表之中插入两种不同的数据

    http://www.cnblogs.com/roucheng/ Android一个ListView列表之中插入两种不同的数据 代码如下: public class ViewHolder{ Butto ...

  5. 从 NavMesh 网格寻路回归到 Grid 网格寻路。

    上一个项目的寻路方案是客户端和服务器都采用了 NavMesh 作为解决方案,当时的那几篇文章(一,二,三)是很多网友留言和后台发消息询问最多的,看来这个方案有着广泛的需求.但因为是商业项目,我无法贴出 ...

  6. Android 组件化/模块化之路——在展示层搭建MVP结构

    Android 组件化/模块化之路——在展示层搭建MVP结构 什么是MVP Model–View–Presenter (MVP) 源于 Model–View–Controller (MVC) 的结构设 ...

  7. CSS Grid 网格布局全解析

    介绍 CSS Grid(网格) 布局使我们能够比以往任何时候都可以更灵活构建和控制自定义网格. Grid(网格) 布局使我们能够将网页分成具有简单属性的行和列.它还能使我们在不改变任何HTML的情况下 ...

  8. python之tkinter使用-Grid(网格)布局管理器

    # 使用tkinter编写登录窗口 # Grid(网格)布局管理器会将控件放置到一个二维的表格里,主控件被分割为一系列的行和列 # stricky设置对齐方式,参数N/S/W/E分别表示上.下.左.右 ...

  9. android搜索框列表布局,流程及主要步骤思维导图

    android搜索框列表布局,流程及主要步骤思维导图 android搜索框列表布局,流程及主要步骤思维导图 activity_coin_search.xml----------<com.scwa ...

随机推荐

  1. Python学习规划

    短时间踏实而高效的学习python 知乎:如何系统的学习python 简书:最全的python学习手册 目录 Python编程语言 python视频教程 Python神经网络算法与深度学习视频教程人工 ...

  2. Java socket1

    注意: 网络编程不是等于网站编程.  html css JavaScript那些是网站编程,是构建在网络编程的基础之上的,网络编程是它的底层.    比方说qq,联动的游戏,这些是网络编程. 一般的网 ...

  3. D. Winter Is Coming 贪心(好题)

    http://codeforces.com/contest/747/problem/D 大概的思路就是找到所有两个负数夹着的线段,优先覆盖最小的长度.使得那时候不用换鞋,是最优的. 但是这里有个坑点, ...

  4. Ubuntu卸载软件包

    sudo apt-get autoremove --purge mysql-server-5.0 ,purge连同配置文件一起删除,autoremove自动卸载依赖包sudo apt-get remo ...

  5. [转]Using the Repository Pattern with ASP.NET MVC and Entity Framework

    本文转自:http://www.codeguru.com/csharp/.net/net_asp/mvc/using-the-repository-pattern-with-asp.net-mvc-a ...

  6. windwsform登录页面

    简单登录设计: 读取用户名密码 数据库表 实体类 数据访问类: 隐藏登录页面: 回车快捷键: 传值到main窗口:

  7. CCF|跳一跳

    import java.util.Scanner; public class Main { public static void main (String[] args) { Scanner scan ...

  8. 了解移动用户的隐私期望:一种基于推荐的Crowdsourcing方法

    应学习之需,最近一段时间阅读了一篇论文,特写下总结,若有纰漏,还望指出. 目录 引言 推荐机制 实现 评估 心得 1.1 为什么要了解移动用户的隐私期望 1.移动设备的广泛使用存在一些潜在的隐私威胁和 ...

  9. darknet+opencv在windows上的编译

    darknet 源码网站:https://github.com/pjreddie/darknet 技术支持官网:https://pjreddie.com/darknet/ darknet采用C++编写 ...

  10. Jenkins .NET项目持续集成配置

    基本步骤 1. 安装并配置MSBUILD 在系统管理->插件管理->添加MSBuild插件 在系统管理->系统设置->找到MSBuild配置部分,配置不同的MSbuild版本 ...