需求:

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. MySQL表中数据的迁移

    INSERT INTO `crm_attachment`(OPERATOR_ID,ATTACHMENT_ID,TYPE ) SELECT APPLICATION_ID ,ATTACHMENT_ID,' ...

  2. Java中时间日期格式化

    1.与日期时间相关的类:      第一:java.util.Date;                           将时间作为一个整体使用.处理时,使用Date类较为简便      第二:j ...

  3. FFmpeg-20160506-snapshot-bin

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

  4. Python~Outlook

    用python处理outlook邮件 按季度将邮件分类,归入新建文件夹2016Q1,2015Q4等等 http://www.tuicool.com/articles/Fra22mq Python读取O ...

  5. 跨浏览器的事件对象-------EventUtil 中的方法及用法

    什么是EventUti----封装好的事件对象 在JavaScript中,DOM0级.DOM2级与旧版本IE(8-)为对象添加事件的方法不同 为了以跨浏览器的方式处理事件,需要编写一段“通用代码”,即 ...

  6. ul 仿 table 循环滚动

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. 【opencv】轮廓相关

    IplImage* contours_rect; IplImage* contours; CvMemStorage* countours_storage=NULL; if(contours_rect= ...

  8. php策略模式的研究

    <?php abstract class Moshi{     private $num;     public $price;     const Ted=1;     const Sed=2 ...

  9. 杨辉三角用java实现

    代码如下: public class ErArray { public static void main(String[] args) { //杨辉三角 int[][] num = new int[1 ...

  10. Java网络连接之HttpURLConnection 与 HttpClient

    HttpClient使用详解:http://blog.csdn.net/wangpeng047/article/details/19624529   注:HttpURLConnection输出流用ou ...