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. jmeter(八)HTTP属性管理器HTTP Cookie Manager、HTTP Request Defaults

    Test Plan的配置元件中有一些和HTTP属性相关的元件:HTTP Cache Manager.HTTP Authorization Manager.HTTP Cookie Manager.HTT ...

  2. React.js 基本环境安装

    安装 React.js React.js 单独使用基本上是不可能的事情.不要指望着类似于 jQuery 下载放到 <head /> 标签就开始使用.使用 React.js 不管在开发阶段生 ...

  3. SQL Server 编程入门

    一.T—SQL 的组成 1.DML(数据操作语言 Data Manipulation Language) 查询.插入.删除和修改数据库中的数据.SELECT.INSERT.UPDATE.DELETE ...

  4. html5移动端适配- media query

    iPad部分css适配 - media query 代码如下图:   注:  @media要放在css最下方,防止被覆盖.  

  5. pandas 选择某几列

    转自:https://blog.csdn.net/aaa_aaa1sdf/article/details/77414387 col_n = ['名称','收盘价','日期'] a = pd.DataF ...

  6. 自定义对话框(jDialog)

    [配置项]jDialog options点击收起 一.接口功能 jDialog的默认配置项,本组件提供的所有对话框,都可以通过修改这些配置项来实现不同的效果. 二.详细配置项 /** * 对话框的默认 ...

  7. ztree 样式修改 white-space: nowrap; 后 下划线要是跟上的话 宽度 width 要 auto 就自动更新了

    width:auto; border-bottom:1px solid #ccc; height:30px; display: inline-block;white-space: nowrap;

  8. spring cloud Bug之was unable to refresh its cache! status = Cannot execute request on any known server

    可能原因: 1.application.yml server: port: 10001spring: application: name: microservice-consumer-movieeur ...

  9. PHP与MySQL的亲密接触

    PHP与MySQL的亲密接触   此篇文章前,你应该先做好一些准备工作 1.建好一个mysql数据库,记住servername,username,password 三者缺一不可. 2.在数据库创建cr ...

  10. source collection list

    1.Anaconda:http://www.cnblogs.com/xiaoming123abc/p/6970890.html https://conda.io/docs/help-support.h ...