首页 > 代码库 > NestedScrollView
NestedScrollView
参考文章:
http://cache.baiducontent.com/c?m=9d78d513d9d431ad4f9d94697b13c0166d4381132ba7d4020cd3843893732b35506793ac51200770a2d20c6d16dc4a48adb0687d6d4566f58cc9fb57c0fed76d38885069324bda5612a544ed9c1a32c157c107b6b247bceaed76c8f997ce8216049650037f81fa8a5c0112c065f51626e3d1c30e4a01&p=9b72da15d9c040ac49f7c7710f5f83&newp=c9759a46d7c014fc57efdc3c4757a5231610db2151d7d4176b82c825d7331b001c3bbfb423241305d6c4786c07a54c5ae8fb3575370123a3dda5c91d9fb4c57479dd&user=baidu&fm=sc&query=%B0%B2%D7%BF%B6%A5%B2%BF%D0%FC%B8%A1&qid=dffe63250000292e&p1=5
http://blog.csdn.net/mchenys/article/details/51541306
效果图:
实现步骤:
- 将需要悬浮的layout放到CollapsingToolbarLayout之外,AppBarLayout之内
- 将CollapsingToolbarLayout的app:layout_scrollFlags设置为scroll
- 给滚动的NestedScroolView设置
app:layout_behavior="@String/appbar_scrolling_view_behavior"
就大功告成了(记得根布局要是CoordinatorLayout)
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="com.example.administrator.scroll4.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="220dp" app:contentScrim="#000000" app:layout_scrollFlags="scroll"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:background="#987545" android:gravity="center" android:text="banner区域" android:textColor="#ffffff" /> </android.support.design.widget.CollapsingToolbarLayout> <TextView android:layout_width="match_parent" android:layout_height="30dp" android:gravity="center" android:text="悬浮的部分" /> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <com.example.administrator.scroll4.MyListView android:id="@+id/lv" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout>
import android.content.Context; import android.util.AttributeSet; import android.widget.ListView; /** * Created by Administrator on 2017/5/5. */ public class MyListView extends ListView { public MyListView(Context context) { super(context); } public MyListView(Context context, AttributeSet attrs) { super(context, attrs); } public MyListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } }
import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.ArrayAdapter; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { private MyListView lv; private List<String> list; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv = (MyListView) findViewById(R.id.lv); list = new ArrayList<>(); for (int i = 0; i < 100; i++) { list.add(i + ""); } ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, list); lv.setAdapter(adapter); } }
NestedScrollView
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。