【问题标题】:How to Expand/Collapse android component in Material Design如何在 Material Design 中展开/折叠 android 组件
【发布时间】:2015-10-28 15:35:00
【问题描述】:
如何展开/折叠 android 组件,如 ImageView、GoogleMap .. 等
我正在使用设计支持库提供android.support.design.widget.CollapsingToolbarLayout 以折叠ToolBar。
但是如何折叠其他组件。
另外我对设计支持库没有深入的了解,如果可以使用CollapsingToolbarLayout 折叠组件,请给我一些示例或示例。
提前致谢。
【问题讨论】:
标签:
android
material-design
android-support-library
【解决方案1】:
CoordinatorLayout 中的视图通过指定这些Behaviors 与其他视图协商以有效地协同工作
CoordinatorLayout 是 Material Design 的一项超酷功能,有助于创建有吸引力且协调的布局。
您所要做的就是将您的子视图包裹在 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.byte64.coordinatorlayoutexample.ScollingActivity">
<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" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_scolling" />
<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 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.byte64.coordinatorlayoutexample.ScollingActivity"
tools:showIn="@layout/activity_scolling">
<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>
这给了我们一个布局,可以滚动折叠工具栏并隐藏 FloatingActionButton
打开:
关闭: