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

3
如何展开/折叠 Android 组件,如ImageViewGoogleMap等。 我正在使用 Design support 库来提供android.support.design.widget.CollapsingToolbarLayout来折叠ToolBar
但是如何折叠其他组件呢? 同时,我对 Design support 库没有深入的了解,如果可以使用CollapsingToolbarLayout来折叠组件,请给我一些示例或样例。 提前致谢。

1
这里有一篇博客可能会对你有所帮助:http://inthecheesefactory.com/blog/android-design-support-library-codelab/en。在支持设计库发布之前,就已经有第三方库发布了。如果你感兴趣的话,可以在Github上找到它们。 - Raghunandan
感谢 @Raghunandan 给出的博客链接。 - Mitesh Vanaliya
1个回答

0

在 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>

这给我们带来的是一个布局,可以滚动折叠工具栏并隐藏浮动操作按钮。
打开:

enter image description here

已关闭:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接