这个,个人建议使用自己写的布局使用view的gon或者visble的方法,使用design包中的控件来的话,局限性很大

方法有倆

(1)自定义ScrollView

重写ScrollView 的 computeScroll()方法 监听滑动,然后去判断你想要的布局是否已经到了顶部,如果到了,其实我最开始就写了两个一模一样的布局一个放在屏幕的最上方只不过一直是隐藏的这个时,就需要把它显示出来就可以了

public class MScrollView extends ScrollView {  

    View v1;
View v2; public MScrollView(Context context) {
super(context);
init();
} public MScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
} public MScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
} @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
init();
} private void init() {
v2 = findViewById(R.id.Weekend2);
} public void setV1(View v1) {
this.v1 = v1;
} @Override
public void computeScroll() {
if (getScrollY() >= v2.getTop()) {
v1.setVisibility(View.VISIBLE);
} else {
v1.setVisibility(View.GONE);
}
super.computeScroll();
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"> <com.example.vsat.test.MScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="星期一" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="星期二" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="星期三" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="星期四" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="星期五" /> <TextView
android:id="@+id/Weekend2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#90C451"
android:gravity="center"
android:text="喂!你醒醒!再坚持一下,马上就周末了" /> <com.example.vsat.test.MListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> </LinearLayout> </com.example.vsat.test.MScrollView> <TextView
android:id="@+id/Weekend1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#90C451"
android:gravity="center"
android:text="喂!你醒醒!再坚持一下,马上就周末了"
android:visibility="gone" />
</RelativeLayout>
public class MainActivity extends Activity {  

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); MScrollView scrollView = (MScrollView) findViewById(R.id.scrollView);
MListView listView = (MListView) findViewById(R.id.listView);
View v = findViewById(R.id.Weekend1);
scrollView.setV1(v);
ArrayList<String> list = new ArrayList<>();
for (int i = 0; i < 20; i++) {
list.add("第" + i + "号机器人");
} ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_expandable_list_item_1,
list);
listView.setAdapter(adapter);
listView.setFocusable(false);
} }

(2)这种只是给无奈用了design的人使用的

附上链接:http://www.jianshu.com/p/abdb9828a00d

    1. 将需要悬浮的layout放到CollapsingToolbarLayout之外,AppBarLayout之内
    2. 将CollapsingToolbarLayout的app:layout_scrollFlags设置为scroll
    3. 给滚动的NestedScroolView设置
      app:layout_behavior="@String/appbar_scrolling_view_behavior"
      就大功告成了(记得根布局要是CoordinatorLayout)

这种方法如果是要固定下拉列表等等比较复杂的布局,就会很是尴尬

最新文章

  1. 【Android】不依赖焦点和选中的TextView跑马灯【2】
  2. Mac OS 下 eclipse中文乱码解决方法(eclipse for mac 中文乱码)
  3. 使用Rsync进行文件的同步与备份
  4. Centos修改镜像为国内的163源
  5. for循环与for in循环
  6. Dubbo 源码安装与编译
  7. Delphi CxGrid 汇总(2)
  8. BZOJ1821: [JSOI2010]Group 部落划分
  9. MAX16054
  10. WPF中实现根据拼音查找汉字
  11. layout_weight 的解释及使用
  12. PowerDesigner建模应用(二)逆向工程,导出PDM文件前过滤元数据(表、视图、存储过程等)
  13. 总结下Redux
  14. 关于局域网 手机连接apache服务器报403forbidden错误参考如下2017.6.6
  15. PowerDesigner设置一对一关系
  16. React 添加对 Less 的支持, 使用 create-react-app 脚手架
  17. display:inline-block与float
  18. JAVA操作mysql
  19. SQL Server上DBLINK的创建,其实很简单!(上)
  20. 【Leetcode】179. Largest Number

热门文章

  1. java基础之BigInteger
  2. Python学习day05 - Python基础(3) 格式化输出和基本运算符
  3. elasticsearch 中文API(二)
  4. Vue配置多个跨域目标链接
  5. 跟我一起实战美团网一之[nodemon] app crashed - waiting for file changes before starting...
  6. [转]模块化——Common规范及Node模块实现(二)
  7. 工控安全入门(六)——逆向角度看Vxworks
  8. ArcGIS Server 10.1安装、配置、发布地图服务
  9. 仓库盘点功能-ThinkPHP_学习随笔
  10. day1(老男孩-Python3.5-S14期全栈开发)