Andorid Scrolling Activity(CoordinatorLayout详情)
2024-10-21 10:35:23
1.new project -> Scrolling Activity
2.Layout xml code
activity_scrolling.xml
<?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.eve.coordinatorlayoutsample.ScrollingActivity"> <android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"> <android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"> <android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" /> <ImageView
android:src="@mipmap/bird"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:minHeight="?attr/actionBarSize"/> </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout> <include layout="@layout/content_scrolling" /> <android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="@android:drawable/ic_dialog_email" /> </android.support.design.widget.CoordinatorLayout>
content_scrolling.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.eve.coordinatorlayoutsample.ScrollingActivity"
tools:showIn="@layout/activity_scrolling"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:text="@string/large_text" /> </android.support.v4.widget.NestedScrollView>
3.Activity code
public class ScrollingActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrolling);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
}
最新文章
- hdu5651 xiaoxin juju needs help (多重集的全排列+逆元)
- 分布式大数据高并发的web开发框架
- [持续更新] 文章列表 last updated SEP 18, 2016
- PHP $_SERVER的详细参数及说明
- APACHE如何里一个站点绑定多个域名?用ServerAlias
- [转]2-SAT问题及其算法
- JFreeChart入学教程
- POP动画引擎中Layer与CALayer的一点区别
- Linux SCP命令复制传输文件的用法
- JDK8新特性面试
- JDBC进阶
- JAVA之JDBC的简单使用(Mysql)
- 用swing做一个简单的正则验证工具
- 洛谷P4316 绿豆蛙的归宿
- DBS:CUPhone
- django之setup()
- java中 this 关键字的三种用法
- wagon-maven-plugin实现自动打包部署到服务器
- Postman 常用测试结果验证及使用技巧
- SpringBoot (四) :thymeleaf 使用详解