需求:

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隐藏和显示顶部布局的更多相关文章

  1. ListView使用item显示不同布局

    /** * 自定义城市列表适配器 */ private class MyCityListAdapter extends BaseAdapter { final int VIEW_TYPE = 2; f ...

  2. NestedScrollView嵌套RecycleView 滑动 实现上滑隐藏 下滑显示头部效果

    废了好大的劲才弄好的,记下来 方便以后查看 public class MainActivity extends AppCompatActivity { private RecyclerView mRe ...

  3. 原生JS实现全屏切换以及导航栏滑动隐藏及显示——重构前

    思路分析: 向后滚动鼠标滚轮,页面向下全屏切换:向前滚动滚轮,页面向上全屏切换.切换过程为动画效果. 第一屏时,导航栏固定在页面顶部,切换到第二屏时,导航条向左滑动隐藏.切换回第一屏时,导航栏向右滑动 ...

  4. Android ListView滑动过程中图片显示重复错乱闪烁问题解决

    最新内容建议直接访问原文:Android ListView滑动过程中图片显示重复错乱闪烁问题解决 主要分析Android ListView滚动过程中图片显示重复.错乱.闪烁的原因及解决方法,顺带提及L ...

  5. jQuery效果之隐藏与显示、淡入淡出、滑动、回调

    隐藏与显示 淡入淡出 滑动效果

  6. JQuery: JQuery效果(隐藏、显示、切换,滑动,淡入淡出,以及动画)

    JQuery:效果 JQuery效果有很多,包括隐藏.显示.切换,滑动,淡入淡出,以及动画等.隐藏:JQuery hide() 显示:JQuery show() 切换:JQuery toggle() ...

  7. 设置DIV隐藏与显示,表格滑动条

    问题描述:         现在希望使用JS设置DIV块的显示与隐藏,当某一个事件触发是,自动显示DIV块,显示表格数据,但是要求表格显示滑动条 问题解决:   (1)DIV块的隐藏与显示 如上所示, ...

  8. jQuery效果:隐藏、显示、切换、滑动、淡入淡出、动画

    jQuery效果 隐藏.显示.切换.滑动.淡入淡出.以及动画 1.隐藏与显示(改变:display:none;) hide()--隐藏 show()--显示 toggle()方法:可以使用它来切换hi ...

  9. Android上下左右滑动,显示底层布局

    转载博客地址:http://www.cnblogs.com/flyme2012/p/4106308.html 闲着没事做了一个小东西.Android的上下左右滑动,显示底层布局.可以做类似于QQ消息列 ...

随机推荐

  1. SQL Server 2005中的分区表

    记录笔记: 转自 猪八戒学做网站 SQL Server 2005中的分区表(一):什么是分区表?为什么要用分区表?如何创建分区表? SQL Server 2005中的分区表(二):如何添加.查询.修改 ...

  2. 6.js模式-中介者模式

    1. 中介者模式 所有对象通过中介者进行通信 var playDirector = (function(){ var players = []; var options = {}; options.a ...

  3. ffmpeg-20160629-git-bin.7z

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...

  4. Bundle savedInstanceState的作用

    写过Android程序的都知道Activity中有一个名称叫onCreate的方法.该方法是在Activity创建时被系统调用,是一个Activity生命周期的开始.可是有一点容易被忽视,就是onCr ...

  5. centos 6.5 配置LDAP服务器+客户端!

    各种度娘!各种歌哥!网上教程参差不齐,历时1天,终于完成,不敢独享,遂,总结分享之,有问题可以留言,知无不言...开始吧 Note: 本次配置的服务器环境是<redhat enterprise ...

  6. WIN7 64位系统下,右下角的声音和电源图标不见的解决办法

    近日,电脑突然出现任务栏右下角的声音和电源图标消失不见的问题,重启仍旧没有修复,后来找到了解决办法 解决办法: 1.Ctrl+Shift+Esc键调出windows资源管理器. 2.找到进程中的exp ...

  7. C# 类中索引器的使用二

    索引器(Indexer)是C#引入的一个新型的类成员,它使得类中的对象可以像数组那样方便.直观的被引用.索引器非常类似于属性,但索引器可以有参数列表,且只能作用在实例对象上,而不能在类上直接作用.定义 ...

  8. iOS 短信分享 邮件分享

    本地调用短信分享. #import "shareViewController.h" @interface shareViewController (){ UIAlertView * ...

  9. Android 菜单定制使用小结

    GridView 添加 ArrayAdapter<Bean>, 在 gridView 的 Item 点击之后, 1.list.add(bean)/remove(bean) 2.adapte ...

  10. SQL 映射的 XML 文件

    MyBatis 真正的力量是在映射语句中.这里是奇迹发生的地方. 对于所有的力量, SQL映射的 XML 文件是相当的简单.当然如果你将它们和对等功能的 JDBC 代码来比较,你会发现映射文件节省了大 ...