滑动listview隐藏和显示顶部布局
需求:
1.listview向下滑动时,隐藏顶部布局
2.listview向上滑动到最上面,显示顶部布局
3.顶部布局的隐藏和显示有过渡效果
4.第一次加载listview时,顶部不要隐藏
布局:
注意:android:animateLayoutChanges="true"添加在需要隐藏显示布局的父布局中才能有过渡效果
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/personal_card_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:descendantFocusability="blocksDescendants"
tools:context="com.xuehu365.xuehu.ui.activity.PersonalCardActivity"> <include
android:id="@+id/title"
layout="@layout/mine_title_layout" /> <LinearLayout
android:id="@+id/personal_card_information"
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_below="@id/title"
android:gravity="center_horizontal"
android:orientation="vertical"> <com.xuehu365.xuehu.ui.widget.CircleImageView
android:id="@+id/personal_card_image"
android:layout_width="78dp"
android:layout_height="78dp"
android:layout_marginTop="23dp"
android:src="@mipmap/bg_touxiang" /> <TextView
android:id="@+id/personal_card_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:textColor="@color/my_font"
android:textSize="16sp" /> <TextView
android:id="@+id/personal_card_company"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textColor="@color/my_gray_font"
android:textSize="14sp" /> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="23dp"
android:layout_marginTop="5dp"
android:orientation="horizontal"> <TextView
android:id="@+id/personal_card_department"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/my_gray_font"
android:textSize="14sp" /> <TextView
android:id="@+id/personal_card_between"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:textColor="@color/my_gray_font"
android:textSize="14sp"
android:visibility="gone" /> <TextView
android:id="@+id/personal_card_duty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/my_gray_font"
android:textSize="14sp" /> </LinearLayout>
</LinearLayout> <LinearLayout
android:id="@+id/personal_card_tabs"
android:layout_width="match_parent"
android:layout_height="43dp"
android:layout_below="@id/personal_card_information"
android:background="@color/white"
android:orientation="horizontal"> <RelativeLayout
android:id="@+id/personal_share_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"> <TextView
android:id="@+id/personal_share"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="看过的直播"
android:textColor="@color/my_gray_font"
android:textSize="18sp" /> <View
android:id="@+id/personal_share_line"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_alignParentBottom="true"
android:background="@color/my_blue" />
</RelativeLayout> <RelativeLayout
android:id="@+id/personal_community_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"> <TextView
android:id="@+id/personal_community"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="加入的社群"
android:textColor="@color/my_gray_font"
android:textSize="18sp" /> <View
android:id="@+id/personal_community_line"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_alignParentBottom="true"
android:background="@color/white" />
</RelativeLayout>
</LinearLayout> <android.support.v4.view.ViewPager
android:id="@+id/personal_card_vp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/personal_card_tabs"
android:descendantFocusability="blocksDescendants"></android.support.v4.view.ViewPager>
</RelativeLayout>
代码
private int oldIndex;
private int newIndex;
private boolean isFirstScroll; //列表滑动监听隐藏信息布局
personal_card_lv.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
switch (scrollState) {
case SCROLL_STATE_TOUCH_SCROLL:
oldIndex = view.getLastVisiblePosition();
break;
}
} @Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
newIndex = view.getLastVisiblePosition();
LogHelp.i("scroll", "newIndex:" + newIndex + "--oldIndex:" + oldIndex);
//往下滑
if (newIndex > oldIndex && firstVisibleItem > 0) {
isFirstScroll = true;
((PersonalCardActivity) getActivity()).personal_card_information.setVisibility(View.GONE);
} else if (firstVisibleItem == 0 && isFirstScroll == true) {
//往上滑
((PersonalCardActivity) getActivity()).personal_card_information.setVisibility(View.VISIBLE);
}
}
});
滑动listview隐藏和显示顶部布局的更多相关文章
- ListView使用item显示不同布局
/** * 自定义城市列表适配器 */ private class MyCityListAdapter extends BaseAdapter { final int VIEW_TYPE = 2; f ...
- NestedScrollView嵌套RecycleView 滑动 实现上滑隐藏 下滑显示头部效果
废了好大的劲才弄好的,记下来 方便以后查看 public class MainActivity extends AppCompatActivity { private RecyclerView mRe ...
- 原生JS实现全屏切换以及导航栏滑动隐藏及显示——重构前
思路分析: 向后滚动鼠标滚轮,页面向下全屏切换:向前滚动滚轮,页面向上全屏切换.切换过程为动画效果. 第一屏时,导航栏固定在页面顶部,切换到第二屏时,导航条向左滑动隐藏.切换回第一屏时,导航栏向右滑动 ...
- Android ListView滑动过程中图片显示重复错乱闪烁问题解决
最新内容建议直接访问原文:Android ListView滑动过程中图片显示重复错乱闪烁问题解决 主要分析Android ListView滚动过程中图片显示重复.错乱.闪烁的原因及解决方法,顺带提及L ...
- jQuery效果之隐藏与显示、淡入淡出、滑动、回调
隐藏与显示 淡入淡出 滑动效果
- JQuery: JQuery效果(隐藏、显示、切换,滑动,淡入淡出,以及动画)
JQuery:效果 JQuery效果有很多,包括隐藏.显示.切换,滑动,淡入淡出,以及动画等.隐藏:JQuery hide() 显示:JQuery show() 切换:JQuery toggle() ...
- 设置DIV隐藏与显示,表格滑动条
问题描述: 现在希望使用JS设置DIV块的显示与隐藏,当某一个事件触发是,自动显示DIV块,显示表格数据,但是要求表格显示滑动条 问题解决: (1)DIV块的隐藏与显示 如上所示, ...
- jQuery效果:隐藏、显示、切换、滑动、淡入淡出、动画
jQuery效果 隐藏.显示.切换.滑动.淡入淡出.以及动画 1.隐藏与显示(改变:display:none;) hide()--隐藏 show()--显示 toggle()方法:可以使用它来切换hi ...
- Android上下左右滑动,显示底层布局
转载博客地址:http://www.cnblogs.com/flyme2012/p/4106308.html 闲着没事做了一个小东西.Android的上下左右滑动,显示底层布局.可以做类似于QQ消息列 ...
随机推荐
- ffmpeg-20160525-git-bin
ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...
- mybatis参数错误 Parameter '×××' not found. Available parameters are [0, 1, param1, param2]
报错的代码 @Update("update staff_info set ApplyState = #{applyState} where Id = #{userId}") int ...
- mybatis延迟加载
配置完成后可能会报错Cannot enable lazy loading because CGLIB is not available. Add CGLIB to your classpath 是由于 ...
- 【C语言】pragma
① #pragma comment (lib, "libgsl.a") 这是告诉编译器在编译形成的.obj文件和.exe文件中加一条信息,使得 链接器在链接库的时候要去找libgs ...
- Hyper snap
图像->分辨率,设置成300dpi,一般论文的分辨率要求.
- 3dmax导出3ds具有过多要导出的面超过64k解决方法
参考:http://blog.sina.com.cn/s/blog_7a71dd090100w3r0.html 修改器->网格编辑->ProOptimizer 选中对象, 原始模型 顶点数 ...
- ssh配置免密码登录
日常工作中很多情况下都需要登录服务器进行管理,一般都是用ssh进行连接,为了防止密码外泄,可以配置下ssh的免密码登录. 首先服务器两台: A:43.224.34.* B:104.238.161.* ...
- nyoj998(euler)
题意:题意:给出n和m,求满足条件gcd(x, n)>=m的x的gcd(x, n)的和,其中1<=x<=n,1<= n, m <= 1e9:思路:此题和nyoj1007差 ...
- DB2 bind on z/os
BIND and REBIND options for packages and plans There are several options you can use for binding or ...
- java向oracle数据库中插入当前时间
public class Test{public static void main (String args []){ java.util.Date a = new java.util.Date(); ...