小编Cod*_*ior的帖子

用户滚动时,如何在工具栏中为视图设置动画?

我想在我的应用程序中添加一些动画.请找到附带的照片以获得动画创意.

工具栏是购物车图标矩形,search_layout在其下方.

我用过CoordinatorLayout.我的搜索布局和工具栏托管在AppBarLayout/CollapsingToolbarLayout中.下面是我的NestedScrollView托管片段.

当用户使用滚动标志滚动时,我能够隐藏搜索布局.我正在尝试实现一个CoordinatorLayout.Behavior,它将开始向左移动购物车图标并开始搜索图标从0到1缩放; 一旦用户滚动并且搜索布局开始隐藏.当搜索布局完全隐藏时,我想在第二个屏幕中显示工具栏.当用户向下滚动并且通过向右移动推车并缩小搜索图标开始显示搜索布局时,它将返回到原始状态,如第一个屏幕所示.

最初我将工具栏上的搜索图标设为隐藏,购物车图标和搜索图标位于线性布局内.

请找到我的xml activity_home_page.xml

<?xml version="1.0" encoding="utf-8"?>
<com.example.ui.customviews.CustomDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/ab_app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="131dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <LinearLayout
                    android:id="@+id/ll_search_layout"
                    android:layout_width="match_parent"
                    android:layout_height="75dp"
                    android:layout_gravity="bottom"
                    android:orientation="vertical"
                    android:visibility="visible"
                    app:layout_scrollFlags="scroll|snap">

                    <LinearLayout
                        android:id="@+id/ll_search_box"
                        android:layout_width="match_parent"
                        android:layout_height="51dp"
                        android:layout_marginBottom="@dimen/dimen_12_dp"
                        android:layout_marginLeft="@dimen/dimen_8_dp"
                        android:layout_marginRight="@dimen/dimen_8_dp"
                        android:layout_marginTop="@dimen/dimen_12_dp"
                        android:background="@drawable/round_corner_layout_white"
                        android:elevation="@dimen/dimen_5_dp"
                        android:focusableInTouchMode="true"
                        android:orientation="horizontal">

                        <EditText
                            android:id="@+id/et_search"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_gravity="center"
                            android:layout_marginLeft="@dimen/dimen_15_dp"
                            android:layout_weight="80"
                            android:background="@android:color/transparent"
                            android:hint="Search for Products"
                            android:padding="@dimen/dimen_5_dp"
                            android:textColor="@color/black"
                            android:textColorHint="@color/hint_text_color"
                            android:textSize="@dimen/dimen_text_16_sp" />

                        <ImageView
                            android:id="@+id/iv_search_icon"
                            android:layout_width="@dimen/dimen_22_dp"
                            android:layout_height="@dimen/dimen_24_dp"
                            android:layout_gravity="center"
                            android:layout_marginLeft="@dimen/dimen_17_dp"
                            android:layout_marginRight="@dimen/dimen_20_dp"
                            android:src="@drawable/ic_search_grey" />
                    </LinearLayout>

                </LinearLayout>

                <include
                    layout="@layout/layout_primary_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/toolbar_primary_height"
                    android:layout_gravity="top" …
Run Code Online (Sandbox Code Playgroud)

animation android android-animation objectanimator

6
推荐指数
1
解决办法
2900
查看次数

android.app.RemoteServiceException:从包中发布错误通知.无法展开RemoteViews:StatusBarNotification

我已经使用RemoteViews小部件实现了自定义通知.我在Android 5.0.2和Android 6.0上测试过它.它工作正常.但过了一段时间,它每次收到GCM的通知时都会崩溃.

崩溃转储 -

Process: package.name, PID: 27743
android.app.RemoteServiceException: Bad notification posted from package package.name: Couldn't expand RemoteViews for: StatusBarNotification(pkg=package.name user=UserHandle{0} id=1524095391 tag=null key=0|package.name|1524095391|null|10247: Notification(pri=0 contentView=package.name/0x7f040033 vibrate=null sound=null defaults=0x0 flags=0x10 color=0x00000000 category=recommendation vis=PUBLIC))
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Run Code Online (Sandbox Code Playgroud)

我的RemoteViews布局在LinearLayout中有Imageview,自定义TextView类扩展TextView.

我创建通知的代码是

    private void showCustomNotification(ABCNotification notification) {
        RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.layout_notification);
        PendingIntent contentPendingIntent = PendingIntent.getBroadcast(mContext, 0, notification.getContentIntent(), PendingIntent.FLAG_UPDATE_CURRENT);

                NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
                builder.setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(contentPendingIntent);

                // Set Notification Priority
                builder.setPriority(notification.getNotificationPriority()); …
Run Code Online (Sandbox Code Playgroud)

notifications android push-notification remoteview custom-notification

4
推荐指数
1
解决办法
4960
查看次数