小编C N*_*ick的帖子

什么触发了View的measure()被调用

在我的应用程序中,我在View的onMeasure()覆盖之一上有一个无限循环.从我的onMeasure中的断点开始调试源代码,我能够一直跟踪堆栈跟踪到PhoneWindow $ DecorView的measure()(我的View Hierarchy中最顶级的类),它由ViewRoot调用.performTraversals().现在,如果我继续踩过来,我最终会通过Looper.loop()类中的消息再次调用PhoneWindow $ DecorView的measure().我猜是有些东西排队了一条需要重新测量的消息,比如无效.

我的问题是,什么触发了一个度量调用需要在View上发生?

根据我对布局/测量/绘制过程的理解,这只会在特定视图上调用invalidate()方法时发生,并且会逐渐减少并执行该视图无效的布局/测量/绘制过程以及所有它的孩子.我会假设我的视图层次结构中的最顶层视图无效.

但是,我已经明确地对每一个无效的调用设置了一个断点,并且没有以某种无限的方式调用invalidate.所以我认为不是这样的.是否有其他方法可以触发测量通过?内部可以触发这个吗?在看到无限无效之后,我有点想法了.

layout android measure

43
推荐指数
2
解决办法
4万
查看次数

FrameLayout显示在AppBarLayout上方

我有一个简单CoordinatorLayout的a AppBarLayoutFrameLayout,但是无论layout_behavior属性如何,FrameLayout内容都显示在.我已经尝试在其他地方添加该属性(比如我的),但这是相同的行为.AppBarLayoutFrameLayoutRecyclerView

这是一张显示我的意思的图片.

在此输入图像描述

活动布局:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:layout_scrollFlags="scroll|enterAlways"/>

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

    <FrameLayout
        android:id="@android:id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

片段布局:

<android.support.v7.widget.RecyclerView
android:id="@+id/checkins_recycler_view"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
Run Code Online (Sandbox Code Playgroud)

我如何在Activity中添加我的片段:

final UserCheckinsFragment fragment = new UserCheckinsFragment();
    final Bundle arguments = new Bundle();
    UserCheckinsFragment.getArguments(arguments, items);
    fragment.setArguments(arguments);

    getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment,
            UserCheckinsFragment.class.getName()).commit();
Run Code Online (Sandbox Code Playgroud)

android android-toolbar android-design-library android-coordinatorlayout

5
推荐指数
1
解决办法
2526
查看次数