canyinghao / CanRefresh

可适配所有视图的下拉刷新上拉加载,并支持各种风格。
Apache License 2.0
350 stars 82 forks source link

layout_height="wrap_content"和emptyview 两个需求 #8

Closed lindaojiang closed 7 years ago

lindaojiang commented 7 years ago

这项目很不错,但我想要更好

1. layout_height

com.canyinghao.canrefresh.CanRefreshLayoutandroid:layout_height以及 <android.support.v7.widget.RecyclerView android:id="@id/can_content_view" android:layout_width="match_parent" android:layout_height="match_parent"android:layout_height 试过只能设置为android:layout_height="match_parent",能不能支持设置为wrap_content
意思是CanRefreshLayout和RecyclerView的高度随着RecyclerView的item数量变化,
比如RecyclerView的item数量是2个,CanRefreshLayout就是2个item高度,下边不会有空白;RecyclerView item数量是1个,CanRefreshLayout就是1个item高度,下边不会有空白;RecyclerView item数量是200个,CanRefreshLayout就是默认的最大高度,比如半屏。

2. emptyview

比如我的emptyview 一个无网络,一个无搜索结果, 无搜索结果,同时也要支持下拉刷新,就不能和RecyclerView放同一个CanRefreshLayout下边,emptyview也不放在RecyclerView里边
emptyview里有一个imageview,一个texitview和一个button,比如 <RelativeLayout android:id="@+id/noNetwork" <ImageView .../> <TextView 网络不给力.../> <Button 点击重试.../>

现在我是放2个CanRefreshLayout,一个CanRefreshLayout下边是RecyclerView,一个CanRefreshLayout是无结果无网络的emptyview,能不能支持把emptyview和RecyclerView放一起;我有个项目同一个activity多子页面用了好多个CanRefreshLayout感觉太土了。

以上有app参考,汽车之家的“二手车之家”app(che168.com), 安装运行后在首页(底部是首页、买车、卖车、工具、我的),点‘买车’,
在买车页右上角点地图那个图标,然后地图上随便点1-3个车源的点,出来的列表高度是可变的,最大高度半屏,同时支持下拉刷新,无网络页面。

canyinghao commented 7 years ago

我看了你说的“二手车之家”app。 1.你要设置高度,给CanRefreshLayout设置不就行了,为何需要给RecyclerView设置。你判断一下个数,然后设置CanRefreshLayout高度就行了。支持wrap_content很麻烦,能不能成也不知道,我不打算做。 2.给RecyclerView设置emptyview可参考RecyclerViewEmpty 你可以反编译“二手车之家”app,看看它怎么实现的,很可能它不是按你想的那种方式实现的。 很可能它的每一项item是固定了高度的,比如100dp,当无网络或者为空时,直接显示一个emptyview,它与RefreshLayout、RecyclerView没任何关系,当大于3个时,设置高度为屏幕高度的一半。其它情况用100dp乘以数量,把这个高度设置给RefreshLayout就行了。

lindaojiang commented 7 years ago

先这样用吧