需求:

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. FFPlay-noConsole-ver-20160409-snapshot

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

  2. 8.SpringMVC参数传递

    页面参数传递到controller, 可被同名(与页面标签上的name名对应)的参数接收,用request设值,页面再取出来. 注意乱码解决办法: ①如果是get提交,则在tomcat的server. ...

  3. mybatis参数错误 Parameter '×××' not found. Available parameters are [0, 1, param1, param2]

    报错的代码 @Update("update staff_info set ApplyState = #{applyState} where Id = #{userId}") int ...

  4. 【leetcode】triangle(easy)

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  5. 让view 覆盖导航栏

    当我们想做一个弹出式菜单时,想将导航栏也一起盖住不显示的话,可以用如下语句实现: UIView* myView = /* 你自定义的view */; UIWindow* currentWindow = ...

  6. 构建新版本APP上传流程

    //既然是构建新版本的 APP,那么所有的证书都是已经存在了的,因此以下不再重复描述证书申请过程,如有需要请自行 Google 相关流程. 1)更改版本号: 2)去掉工程内的全局断点,同时关闭僵尸调试 ...

  7. solrconfig.xml和schema.xml说明

    1.   solrconfig.xml solrconfig.xml配置文件主要定义了SOLR的一些处理规则,包括索引数据的存放位置,更新,删除,查询的一些规则配置. 1.1.  datadir节点 ...

  8. EasyUI中控件汉化问题

    --BY ZYZ 我在使用EasyUI的过程中,遇到了控件无汉化的情况,如下图. 这么多洋文看着觉得挺烦的.时间居然是月日年格式的,这样可不行,得改. 重写控件代码?别,那能是我这种低级代码C-V客能 ...

  9. Html和CSS的关系

    1. HTML是网页内容的载体.内容就是网页制作者放在页面上想要让用户浏览的信息,可以包含文字.图片.视频等. 2. CSS样式是表现.就像网页的外衣.比如,标题字体.颜色变化,或为标题加入背景图片. ...

  10. Chrome Crx 插件下载

    扯蛋的GFW屏蔽了google域导致下载Chrome插件加载失败,本人想收集以些chrome的Crx插件,可供直接下载 XMarks - 在不同电脑不同浏览器之间同步书签 下载地址:   http:/ ...