我有一个折叠的工具栏布局,其中包含一些文本视图,并且在折叠时显示包含textview的工具栏。它完全按照我想要的方式工作,但每当我折叠工具栏时都会显示重复生成的错误日志。
布局:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:collapsedTitleGravity="center"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleEnabled="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/_5dp"
android:layout_marginLeft="@dimen/_15dp"
android:layout_marginRight="@dimen/_15dp"
android:layout_marginTop="@dimen/_5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="a"
android:textColor="@color/white" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal">
<TextView
android:id="@+id/arates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="arates"
android:textColor="@color/white"/>
<TextView
android:id="@+id/aimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_5dp"
android:textColor="@color/bitupcolor"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="B"
android:textColor="@color/white" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal">
<TextView
android:id="@+id/brates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=brates"
android:textColor="@color/white"/>
<TextView
android:id="@+id/bimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_5dp"
android:textColor="@color/bitdowncolor"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/btntoolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/_30dp"
app:layout_collapseMode="pin">
<LinearLayout
android:id="@+id/llcollapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clickable="true">
<TextView
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:clickable="true"
android:gravity="center"
android:layout_gravity="center"
android:text="dscbckbsZ"
android:textSize="@dimen/_12dp"
android:visibility="gone" />
<TextView
android:id="@+id/down"
android:layout_width="@dimen/_12dp"
android:layout_height="@dimen/_12dp"
android:layout_gravity="center"
android:background="@mipmap/ic_down"
android:gravity="center"
android:clickable="true"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Java功能
private void dynamicAppbar() {
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
boolean isShow = false;
int scrollRange = -1;
@Override
public void onOffsetChanged(final AppBarLayout appBarLayout, final int verticalOffset) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (scrollRange == -1) {
scrollRange = appBarLayout.getTotalScrollRange();
}
if (scrollRange + verticalOffset == 0) {
live_btn.setVisibility(View.VISIBLE);
live_btn.setText(getResources().getString(R.string.live_price));
separator.setVisibility(View.VISIBLE);
down.setVisibility(View.VISIBLE);
initListener();
isShow = true;
} else if (isShow) {
separator.setVisibility(View.GONE);
live_btn.setVisibility(View.GONE);
down.setVisibility(View.GONE);
isShow = false;
}
}
});
}
});
}
错误
requestLayout() improperly called by android.support.design.widget.CollapsingToolbarLayout{23967ac8 V.ED.... ........ 0,0-720,190 #7f0c0078 app:id/collapsing_toolbar} during second layout pass: posting in next frame
requestLayout() improperly called by android.support.v7.widget.AppCompatTextView{3f2b6761 V.ED..C. ........ 254,0-434,33 #7f0c008a app:id/btn} during second layout pass: posting in next frame
requestLayout() improperly called by android.support.design.widget.CollapsingToolbarLayout{23967ac8 V.ED.... ........ 0,0-720,190 #7f0c0078 app:id/collapsing_toolbar} during second layout pass: posting in next frame
requestLayout() improperly called by android.support.v7.widget.AppCompatTextView