简而言之   为listView设置onScrollListener  当滑动时 firstVisibleItem>=要悬浮的 item的position时 让悬浮部分显示  否则隐藏

其实就是在listView之上用帧布局覆盖了一个 悬浮部分

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sticky);
invis = (LinearLayout) findViewById(R.id.invis); strs = new String[100]; for (int i = 0; i < 20; i++) {
strs[i] = "data-----" + i;
} lv = (ListView) findViewById(R.id.lv);
View header = View.inflate(this, R.layout.stick_header, null);//头部内容
lv.addHeaderView(header);//添加头部
lv.addHeaderView(View.inflate(this, R.layout.stick_action, null));//ListView条目中的悬浮部分 添加到头部 lv.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, strs));
lv.setOnScrollListener(new OnScrollListener() { @Override
public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override
public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) {
if (firstVisibleItem >= 1) {
invis.setVisibility(View.VISIBLE);
} else { invis.setVisibility(View.GONE);
}
}
});
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#332b3b"
android:gravity="center"
android:text="标题"
android:textColor="#ffffff" /> <FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title" > <ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent" /> <LinearLayout
android:id="@+id/invis"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#ccedc7"
android:orientation="horizontal"
android:visibility="gone" > <TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="悬浮部分" />
</LinearLayout>
</FrameLayout> </RelativeLayout>

最新文章

  1. [.net 面向对象编程基础] (22) 事件
  2. 《30天自制操作系统》笔记(03)——使用Vmware
  3. java 堆栈分析3
  4. MongoDB3.0新特性
  5. 数论之高次同余方程(Baby Step Giant Step + 拓展BSGS)
  6. ylb:SQL Server中的时间函数
  7. Javascript oop深入学习笔记(三)--javascript中类的实现
  8. bzoj2679:[Usaco2012 Open]Balanced Cow Subsets
  9. git设置过滤忽略的文件或文件夹
  10. Windows server 2012 各版本 激活方法
  11. 数据库 版本号是 661,打不开。此server支持 655 和更早的版本号。不支持降级路径
  12. FastJson的用法
  13. A+B problems
  14. Windows Developer Day - Adaptive Cards
  15. Linux:Day4(上) 文件管理、管道
  16. 学习STM32,你不得不了解的五大嵌入式操作系统
  17. 10 Rules of Highly Successful Project Management
  18. SQL备份一张表的数据
  19. Linux CentOS7系统中ssh的用法
  20. centos7上安装 mysql

热门文章

  1. 分布式存储Seaweedfs源码分析
  2. Delphi 字符串截取函数
  3. docker的完整解决方案2
  4. [PC]PHPCMS v9.5.6整合UEditer1.4.2
  5. .net上的 jpa
  6. java NIO 文章
  7. mongodb数据到MySQL数据库 的迁移步骤
  8. java工程师基础笔试题(一)-参考答案
  9. Building and using plug-ins for Android
  10. Spread Syntax