用GridView解决多级目录问题
来源:互联网 发布:非appstore 软件 信任 编辑:程序博客网 时间:2024/06/05 07:31
1、我在开发中遇到很多次多级目录问题,有两级目录、三级目录、四级目录、五级目录等等。。。
解决多级目录有一个问题需要跟后台沟通好,他这个结构数据到底是一次性传递给客户端还是分多次,分多次的意思是一你点击某个目录就传递该目录数据给你。这个很重要。如果是两级目录并且数据的量比较少,无论服务器是一次性传数据给你还是分多次传给你,你都可以用ExpandableListView来做,你可以把一级目录数据一次性获取到,在遍历一级目录,拿到说有二级目录数据,这样你就可以展示了,当然如果他一次性把一级和二级目录数据都传递给你就更好,你就不需要遍历请求了。这只能是当数据量比较小的时候建议这样做,这样加载数据虽然耗时,但是效果还是不错的。
但是往往很多多级目录的数据量比较大,你就不能用ExpandableListView来解决,按照我的经验来说ExpandableListView在本地数据中可以轻松解决三级目录问题,但是在本地数据中到四级目录就很困难了,但是超过三级目录,如果是本地数据可以用TreeView来实现超过三级的目录展示问题。但是开发中很少有可能数据是在本地的,都是从服务器拿来显示的,如果是这样ExpandableListView和TrewView都无法满足需求了,他们准备数据会相当耗时。所以我推荐一个方法,那就是用HorizontalScrollView里面嵌套一个GridView来当做目录头部,下面来一个FrameLayout来加载Fragment显示目录下级数据。
我下面会上传一个图片来方便理解,毕竟文字描述太硬。
以下是XML:
<?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"> <HorizontalScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="18dp" android:scrollbars="none"> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_horizontal" android:orientation="horizontal" android:padding="3dp"> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center" android:orientation="horizontal"> <TextView android:id="@+id/route_name_lv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" android:gravity="center" android:text="总标题" android:textSize="16sp" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="5dp" android:src="@mipmap/arrow_right" /> </LinearLayout> <GridView android:id="@+id/gridView" android:layout_width="wrap_content" android:layout_height="match_parent" /> </LinearLayout> </HorizontalScrollView> <View style="@style/levelLine" /> <FrameLayout android:id="@+id/frame_layout" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>上面的XML里面的levelLine是一个普通的横线,在res/values/style.xml里面写的:
<!--横向线条--> <style name="levelLine"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">0.3dp</item> <item name="android:background">#ccc</item> </style>
- 用GridView解决多级目录问题
- 在php中用递归的方式创建多级目录(解决多级目录无法直接创建的问题)
- GridVieW控件自定义删除按钮-解决多级相关中删除问题
- android 解压zip与rar--解决多级目录与中文乱码问题
- php设置多级目录session的问题
- Codeigniter 框架多级目录访问问题
- 用C语言创建多级目录
- vc 用mkdir 创建多级目录
- C#实现多级GridView多级数据表
- 适用于多级目录的Makefile(还没试试,改天用了如果有问题,再修改)
- 多级目录数据库设计方案
- 多级目录设计思想
- 创建多级目录
- 如何删除多级目录
- php创建多级目录
- SHCreateDirectoryEx 创建多级目录
- VC创建多级目录
- C++ 创建多级目录
- onSubmit提交验证
- java编程思想读书笔记(二)
- svn精细配置各个目录的权限
- 使用FastJSON,将对象或数组和JSON串互转
- 如何在CentOS 7上修改主机名
- 用GridView解决多级目录问题
- 【editdistance】在Windows环境下配置python库editdistance
- Android studio 报Error:The number of method references in a .dex file cannot exceed 64K错误
- 关于oracle的原生sql排序分页
- Python isdigit()
- iOS自定制导航栏返回按钮或者隐藏导航栏pop手势失效解决方案
- cordova学习一环境搭建(window)
- 6G-SDI xilinx
- Android使用WebView不加载页面(页面空白)