【问题标题】:How to Expand/Collapse android component in Material Design如何在 Material Design 中展开/折叠 android 组件
【发布时间】:2015-10-28 15:35:00
【问题描述】:

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

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

【问题讨论】:

  • 这里有一个博客可以帮助inthecheesefactory.com/blog/…。甚至在支持设计库之前就已经发布了第三方库。如果你有兴趣,可以在 github 上找到它们。
  • 感谢您提供博客链接@Raghunandan...

标签: 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

打开:

关闭:

【讨论】:

    猜你喜欢
    • 2015-04-07
    • 2016-10-12
    • 2021-04-26
    • 2021-03-30
    • 1970-01-01
    • 2021-09-19
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多