2

CollapsingToolbarLayout をトリガーする RecyclerView があり、4.2.2 で折りたたまれたツールバーを再度開いてみると、以下のクラッシュが発生します。何か案は?

java.lang.IllegalArgumentException: width and height must be > 0
        at android.graphics.Bitmap.createBitmap(Bitmap.java:638)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:620)
        at android.support.design.widget.CollapsingTextHelper.ensureExpandedTexture(CollapsingTextHelper.java:405)
        at android.support.design.widget.CollapsingTextHelper.setInterpolatedTextSize(CollapsingTextHelper.java:382)
        at android.support.design.widget.CollapsingTextHelper.calculateOffsets(CollapsingTextHelper.java:227)
        at android.support.design.widget.CollapsingTextHelper.setExpansionFraction(CollapsingTextHelper.java:203)
        at android.support.design.widget.CollapsingToolbarLayout$OffsetUpdateListener.onOffsetChanged(CollapsingToolbarLayout.java:754)
        at android.support.design.widget.AppBarLayout$Behavior.dispatchOffsetUpdates(AppBarLayout.java:851)
        at android.support.design.widget.AppBarLayout$Behavior.setAppBarTopBottomOffset(AppBarLayout.java:834)
        at android.support.design.widget.AppBarLayout$Behavior.scroll(AppBarLayout.java:793)
        at android.support.design.widget.AppBarLayout$Behavior.onNestedScroll(AppBarLayout.java:644)
        at android.support.design.widget.AppBarLayout$Behavior.onNestedScroll(AppBarLayout.java:583)
        at android.support.design.widget.CoordinatorLayout.onNestedScroll(CoordinatorLayout.java:1428)
        at android.support.v4.view.ViewParentCompat$ViewParentCompatStubImpl.onNestedScroll(ViewParentCompat.java:97)
        at android.support.v4.view.ViewParentCompat.onNestedScroll(ViewParentCompat.java:330)
        at android.support.v4.view.NestedScrollingChildHelper.dispatchNestedScroll(NestedScrollingChildHelper.java:162)
        at android.support.v7.widget.RecyclerView.dispatchNestedScroll(RecyclerView.java:8306)
        at android.support.v7.widget.RecyclerView.scrollByInternal(RecyclerView.java:1387)
        at android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2209)
        at android.view.View.dispatchTouchEvent(View.java:7127)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)

アップデート:

クラッシュの原因となるライブラリのメソッドは、高さまたは幅のいずれかが 0 より大きいかどうかのみをチェックしているように見えますが、ビットマップでは両方が > 0 である必要があります。

private void ensureExpandedTexture() {
    if(this.mExpandedTitleTexture == null && !this.mExpandedBounds.isEmpty() && !TextUtils.isEmpty(this.mTextToDraw)) {
        this.mTextPaint.setTextSize(this.mExpandedTextSize);
        this.mTextPaint.setColor(this.mExpandedTextColor);
        int w = Math.round(this.mTextPaint.measureText(this.mTextToDraw, 0, this.mTextToDraw.length()));
        int h = Math.round(this.mTextPaint.descent() - this.mTextPaint.ascent());
        this.mTextWidth = (float)w;
        if(w > 0 || h > 0) {
            this.mExpandedTitleTexture = Bitmap.createBitmap(w, h, Config.ARGB_8888);
            Canvas c = new Canvas(this.mExpandedTitleTexture);
            c.drawText(this.mTextToDraw, 0, this.mTextToDraw.length(), 0.0F, (float)h - this.mTextPaint.descent(), this.mTextPaint);
            if(this.mTexturePaint == null) {
                this.mTexturePaint = new Paint();
                this.mTexturePaint.setAntiAlias(true);
                this.mTexturePaint.setFilterBitmap(true);
            }

        }
    }
}

xml は次のとおりです。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                             xmlns:app="http://schemas.android.com/apk/res-auto"
                                             android:id="@+id/main_content"
                                             android:layout_width="match_parent"
                                             android:layout_height="match_parent"
                                             android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/series_detail_header_image_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:layout_scrollFlags="scroll|exitUntilCollapsed"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleTextAppearance="@style/TransparentText">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax"
            >
            <ImageView
                android:id="@+id/image_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="?attr/colorPrimary"
                android:paddingLeft="20dp"
                android:paddingTop="10dp"
                android:paddingRight="10dp"
                android:layout_gravity="bottom"
                >
                <TextView
                    android:id="@+id/seriesDetailTitle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="American Pickers"
                    android:textColor="@android:color/white"
                    android:textSize="20sp"/>
                <TextView
                    android:id="@+id/seriesDetailTunein"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Tune in tuesdays at 8pm"
                    android:textColor="@android:color/white"
                    android:textSize="18sp"/>
                <LinearLayout
                    android:id="@+id/adFrame"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:paddingRight="@dimen/padding_small"
                    android:visibility="gone">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginRight="@dimen/margin_minimal"
                        android:text="@string/show_detail_presented_by"
                        android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
                        android:textColor="@android:color/white"
                        android:textSize="10sp"
                        android:visibility="visible"/>

                    <FrameLayout
                        android:id="@+id/adView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:visibility="visible"/>
                </LinearLayout>
            </LinearLayout>
        </FrameLayout>
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin"
            />
    </android.support.design.widget.CollapsingToolbarLayout>

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


<android.support.v4.view.ViewPager
    android:id="@+id/show_view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:paddingTop="@dimen/toolbar_height"
    />
<RelativeLayout android:id="@+id/controls"
                android:layout_width="match_parent"
                android:layout_height="@dimen/toolbar_height"
                android:background="@color/app_primary"
                app:layout_collapseMode="pin"
                android:layout_gravity="bottom"
                app:layout_anchor="@id/show_view_pager"
                app:layout_anchorGravity="top"
    >

    <Spinner
        android:id="@+id/season_spinner"
        android:layout_width="124dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="@dimen/series_detail_spinner_left_margin"
        android:prompt="@string/seasons"
        android:spinnerMode="dropdown"
        android:dropDownVerticalOffset="-48dp"
        android:dropDownWidth="124dp"
        android:background="@drawable/selector_spinner_selector_list"
        />

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:clipToPadding="false"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:tabMode="scrollable" />

</RelativeLayout>

私はバグを報告しました:デザイン サポート ライブラリのクラッシュ - CollapsingTextHelper クラス- しかし、誰かがそれまでに修正を持っていれば、私は非常に感謝しています!

4

1 に答える 1

9

I've discovered the cause. In the xml for the CollapsingToolbarLayout I set:

app:expandedTitleTextAppearance="@style/TransparentText"

And the style was:

<style name="TransparentText">
    <item name="android:textColor">#00666666</item>
</style>

So that it would only show the text when the toolbar was collapsed.

Turns out that the styles for expandedTitleTextAppearance and collapsedTitleTextAppearance need to specifically inherit from TextAppearance. So this style works properly:

<style name="TransparentText" parent="@android:style/TextAppearance">
    <item name="android:textColor">#00666666</item>
</style>

Just a heads up for anyone else who makes the same mistake...

Update (7/20/2015): This bug appears to be fixed in v22.2.1 of the Design Support Library (https://code.google.com/p/android/issues/detail?id=178674)

于 2015-07-02T16:31:32.610 に答える