android - 如何在 Material Design 中展开/折叠 android 组件

标签 android material-design android-support-library

如何展开/折叠 android 组件,如 ImageViewGoogleMap 等 我正在使用设计支持库来提供 android.support.design.widget.CollapsingToolbarLayout 来折叠 ToolBar

但是如何折叠其他组件。 此外,我还没有深入了解设计支持库,如果可以使用 CollapsingToolbarLayout 折叠组件,请给我一些示例或示例。 提前致谢。

最佳答案

CoordinatorLayout 中的 View 通过指定这些 Behaviors 与其他 View 协商以便有效地协同工作

CoordinatorLayout 是 Material Design 的一项超酷功能,有助于创建有吸引力且协调的布局。

您所要做的就是将您的 subview 包装在 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>

和内容滚动:

<?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 的布局

打开:

enter image description here

关闭:

enter image description here

关于android - 如何在 Material Design 中展开/折叠 android 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31839626/

相关文章:

android - 在android中运行命令

android - Eclipse Isse 中的 Material 抽屉

android - android 中的 Appcompat-v7 冲突

android - 添加 fragment 和简单的UI元素会大大减慢音频处理算法的速度

android - 我可以维护一个 apk 来处理 Android 上的指纹扫描吗?

java - 如何在editText中放置一个按钮

javascript - 如何在 md-sidenav 中实用地添加或禁用(删除)md-disable-backdrop

android - 从 appcompat-v7 android 中删除图像和 Assets

android - 屏幕超时会破坏文本到语音应用程序

java - 如何在 tablerow 内以编程方式设置 textview 的边距