【问题标题】:How to create a drop down view like Google Calendar using Toolbar?如何使用工具栏创建像谷歌日历这样的下拉视图?
【发布时间】:2015-08-19 22:18:12
【问题描述】:

我正在尝试创建类似于 Google 日历下拉月份小部件的内容。

任何帮助将不胜感激。

到目前为止,我有一个想法,我需要使用带有可扩展动画的工具栏,但不确定这是正确的方向。

【问题讨论】:

  • API折叠工具栏支持的最低级别是多少?
  • 它现在是设计支持库的一部分,所以应该支持 2.3 及更高版本。

标签: android google-calendar-api toolbar dropdownbox


【解决方案1】:

我找到了一个创建下拉视图的项目,例如Google calendar app

使用这个:Sample Project

使用CollapsingToolbarLayout在里面放自定义calenderView

<?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:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:background="@android:color/white"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stateListAnimator="@animator/ann"
        app:expanded="false"
        android:background="@android:color/white"
        app:layout_behavior=".MyAppBarBehavior"
        tools:targetApi="lollipop">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap|enterAlways"
            app:statusBarScrim="?attr/colorPrimaryDark">

            <!--large view -->
            <com.example.GoogleCalendar.GooglecalenderView
                android:id="@+id/calander"
                android:layout_width="match_parent"
                android:layout_height="500dp"
                android:orientation="vertical"
                app:layout_collapseMode="pin"

                android:layout_marginTop="?attr/actionBarSize"
              >


            </com.example.GoogleCalendar.GooglecalenderView>

            <!--top toolbar-->
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:title="fkdl"
                app:contentInsetLeft="0dp"
                app:contentInsetStart="0dp"
                app:titleTextColor="@color/colorPrimaryDark"
                android:background="@android:color/white"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay">

                <android.support.constraint.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:clickable="true"
                    android:focusable="true">

                    <View
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:layout_marginTop="10dp"
                        android:id="@+id/backsupport"
                        android:background="?attr/selectableItemBackground"
                        android:clickable="true"
                        android:layout_marginBottom="10dp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
                <TextView
                        android:id="@+id/monthname"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintBottom_toBottomOf="parent"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:paddingTop="4dp"
                        android:paddingBottom="4dp"
                        android:fontFamily="@font/googlesans_regular"
                        android:text="June"
                        android:textColor="#464646"
                        android:textSize="20sp" />
                    <ImageView
                        android:id="@+id/arrowImageView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_arrow_drop_up_black_24dp"
                        app:layout_constraintLeft_toRightOf="@+id/monthname"
                        android:translationX="-5dp"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintBottom_toBottomOf="parent"
                        tools:ignore="ContentDescription,RtlHardcoded" />
                                 </android.support.constraint.ConstraintLayout>

            </android.support.v7.widget.Toolbar>
  </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <com.example.GoogleCalendar.MyRecyclerView
        android:id="@+id/nestedView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


</android.support.design.widget.CoordinatorLayout>

【讨论】:

    【解决方案2】:

    我还尝试创建类似于 Google 日历应用的东西。我已经有了这个实现:

    我将 CompactCalendarView 库用于月份小部件。 CollapsingToolbarLayout 用于下拉菜单。

    您可以在 GitHub 上查看此实现的源代码:https://github.com/GerritHoekstra/CompactCalendarViewToolbar

    主布局可以找到here

    我希望这对您有所帮助。

    【讨论】:

    • 嘿,我检查了你的代码,它与我的非常相似。我的问题是工具栏的展开动画很慢,你的不是。你是怎么做到的?
    • 我创建了一个问题来询问它:stackoverflow.com/questions/34527357/…
    • 非常感谢!使用视差倍增器的巧妙技巧给了我想要的东西。
    • 如何禁用工具栏拖动,并仅从工具栏按钮控制打开和关闭它?
    • 我检查了您的解决方案,但是我有一个问题。为什么 CompactCalendarView 需要在线性布局中?没有人就不能实施吗?但是,当我没有将其封闭在线性布局中时,它似乎不起作用。
    【解决方案3】:

    你想看看 CollapsingToolbarLayout

    <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:expandedTitleMarginStart="64dp"
                app:contentScrim="?attr/colorPrimary">
                <CalendarView
                    android:layout_width="match_parent"
                    android:layout_height="256dp"></CalendarView>
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:minHeight="?attr/actionBarSize"
                    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:layout_collapseMode="pin"/>
    
            </android.support.design.widget.CollapsingToolbarLayout>
    

    我建议你关注this awesome tutorial 来实现这个和其他关于设计库的有趣的东西。希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-01
      • 1970-01-01
      • 2016-06-28
      • 2014-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-08
      相关资源
      最近更新 更多