Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.68 KB | None | 0 0
  1. 08-12 13:14:19.604 2263-2263/com.panoroma.admin W/View: requestLayout() improperly called by android.support.design.widget.CollapsingToolbarLayout{2d353cd6 V.ED.... ........ 0,0-1080,390 #7f0c0070 app:id/collapsing_toolbar} during second layout pass: posting in next frame
  2. 08-12 13:14:19.604 2263-2263/com.panoroma.admin W/View: requestLayout() improperly called by android.support.v7.widget.AppCompatTextView{1bb84b57 V.ED.... ........ 168,48-407,119 #7f0c0073 app:id/toolbar_title} during second layout pass: posting in next frame
  3.  
  4. <android.support.design.widget.CoordinatorLayout
  5. xmlns:android="http://schemas.android.com/apk/res/android"
  6. xmlns:app="http://schemas.android.com/apk/res-auto"
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent">
  9.  
  10. <android.support.design.widget.AppBarLayout
  11. android:id="@+id/appbar"
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content"
  14. android:theme="@style/AppTheme.AppBarOverlay">
  15.  
  16. <android.support.design.widget.CollapsingToolbarLayout
  17. android:id="@+id/collapsing_toolbar"
  18. android:layout_width="match_parent"
  19. android:layout_height="wrap_content"
  20. app:contentScrim="?attr/colorPrimary"
  21. app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed|exitUntilCollapsed">
  22.  
  23. <ImageView
  24. android:id="@+id/header"
  25. android:layout_width="100dp"
  26. android:layout_height="100dp"
  27. android:adjustViewBounds="true"
  28. android:layout_gravity="center"
  29. android:scaleType="centerCrop"
  30. android:layout_marginTop="15dp"
  31. android:layout_marginBottom="15dp"
  32. android:background="@drawable/dashboard80"
  33. app:layout_collapseMode="parallax"
  34. app:layout_collapseParallaxMultiplier="0.5" />
  35.  
  36. <android.support.v7.widget.Toolbar
  37. android:id="@+id/da_toolbar"
  38. app:popupTheme="@style/AppTheme.PopupOverlay"
  39. app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
  40. xmlns:android="http://schemas.android.com/apk/res/android"
  41. xmlns:app="http://schemas.android.com/apk/res-auto"
  42. android:layout_width="match_parent"
  43. app:layout_collapseMode="pin"
  44. android:layout_height="?attr/actionBarSize">
  45.  
  46. <TextView
  47. android:layout_width="wrap_content"
  48. android:layout_height="wrap_content"
  49. android:textSize="20sp"
  50. android:textColor="?attr/colorAccent"
  51. android:id="@+id/toolbar_title"/>
  52.  
  53. </android.support.v7.widget.Toolbar>
  54.  
  55. </android.support.design.widget.CollapsingToolbarLayout>
  56. </android.support.design.widget.AppBarLayout>
  57.  
  58.  
  59. <ScrollView
  60. android:layout_width="match_parent"
  61. android:layout_height="match_parent"
  62. android:layout_below="@+id/rel_dash_icon"
  63. app:layout_behavior="@string/appbar_scrolling_view_behavior" >
  64.  
  65. .........................
  66.  
  67. </ScrollView>
  68.  
  69. </android.support.design.widget.CoordinatorLayout>
  70.  
  71. Typeface ubuntuC = Typeface.createFromAsset(getAssets(), "ubuntuC.ttf");
  72. Toolbar toolbar = (Toolbar) findViewById(R.id.da_toolbar);
  73. toolbar.setTitle("");
  74. setSupportActionBar(toolbar);
  75.  
  76. toolbar_title = (TextView)toolbar.findViewById(R.id.toolbar_title);
  77. toolbar_title.setTypeface(ubuntuC);
  78.  
  79. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
  80. getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha, null));
  81. else
  82. getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
  83. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  84.  
  85. final CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
  86. AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar);
  87. appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
  88. boolean isShow = false;
  89. int scrollRange = -1;
  90.  
  91. @Override
  92. public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
  93. if (scrollRange == -1) {
  94. scrollRange = appBarLayout.getTotalScrollRange();
  95. }
  96. if (scrollRange + verticalOffset == 0) {
  97. // collapsingToolbarLayout.setTitle("Dashboard");
  98. toolbar_title.setText("Dashboard");
  99. isShow = true;
  100. } else if(isShow) {
  101. // collapsingToolbarLayout.setTitle("");
  102. toolbar_title.setText("");
  103. isShow = false;
  104. }
  105. }
  106. });
  107.  
  108. @Override
  109. public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
  110. getActivity().runOnUiThread(new Runnable() {
  111. @Override
  112. public void run() {
  113. if (scrollRange == -1) {
  114. scrollRange = appBarLayout.getTotalScrollRange();
  115. }
  116. if (scrollRange + verticalOffset == 0) {
  117. collapsingToolbarLayout.setTitle("Dashboard");
  118. toolbar_title.setText("Dashboard");
  119. isShow = true;
  120. } else if(isShow) {
  121. collapsingToolbarLayout.setTitle(" ");
  122. toolbar_title.setText(" ");
  123. isShow = false;
  124. }
  125. }
  126. });
  127.  
  128. app:titleEnabled="false"
  129.  
  130. <style name="CustomCollapsingCollapsed">
  131. <item name="android:textColor">@color/colorText</item>
  132. </style>
  133. <style name="CustomCollapsingExpanded">
  134. <item name="android:textColor">@color/transparent</item>
  135. </style>
  136.  
  137. <android.support.design.widget.CollapsingToolbarLayout
  138. android:layout_width="match_parent"
  139. android:layout_height="match_parent"
  140. app:contentScrim="@color/colorAccent"
  141. app:layout_scrollFlags="scroll|exitUntilCollapsed"
  142. app:expandedTitleTextAppearance="@style/CustomCollapsingExpanded"
  143. app:collapsedTitleTextAppearance="@style/CustomCollapsingCollapsed"
  144. >
  145.  
  146. appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
  147. boolean isShow = false;
  148. int scrollRange = -1;
  149.  
  150. @Override
  151. public void onOffsetChanged(final AppBarLayout appBarLayout, final int verticalOffset) {
  152. if (scrollRange == -1) {
  153. scrollRange = appBarLayout.getTotalScrollRange();
  154. }
  155. if (scrollRange + verticalOffset == 0) {
  156. if (mToolbarTitle.getVisibility() == View.GONE) {
  157. mToolbarTitle.setVisibility(View.VISIBLE);
  158. mCollapsingToolbarLayout.setTitle("昵称");
  159. mToolbarTitle.setText("昵称");
  160. }
  161. isShow = true;
  162. } else if (isShow) {
  163. mToolbarTitle.setVisibility(View.GONE);
  164. isShow = false;
  165. }
  166. }
  167. });
  168.  
  169. mAppBar.addOnOffsetChangedListener(new AppBarStateChangeListener() {
  170. @Override
  171. public void onStateChanged(AppBarLayout appBarLayout, final int state, int done) {
  172. mAppBar.post(new Runnable() {
  173. @Override
  174. public void run() {
  175. if (state == COLLAPSED) {
  176. mToolBarTitle.setText(model.getTitle());
  177. } else if (state == EXPANDED || state == IDLE) {
  178. mToolBarTitle.setText("");
  179. }
  180. }
  181. });
  182. }
  183. });
  184.  
  185. < android.support.v7.widget.Toolbar
  186. android:id="@+id/toolbar"
  187. android:layout_width="match_parent"
  188. android:layout_height="?attr/actionBarSize"
  189. app:layout_collapseMode="pin"
  190. app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
  191.  
  192. <TextView
  193. android:id="@+id/toolbar_title"
  194. style="@style/Toolbar.Title"
  195. android:layout_width="wrap_content"
  196. android:layout_height="wrap_content"
  197. android:visibility="gone"
  198. android:layout_gravity="center" />
  199.  
  200. </android.support.v7.widget.Toolbar>
  201.  
  202. appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
  203. @Override
  204. public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
  205. if (verticalOffset == toolbar.getHeight() - collapsingToolbarLayout.getHeight()) {
  206.  
  207. if (textView.getVisibility() != View.VISIBLE) {
  208. textView.setVisibility(View.VISIBLE);
  209. textView.setText(title); // show toolbar title
  210. }
  211. } else {
  212. if (textView.getVisibility() != View.GONE) {
  213. textView.setVisibility(View.GONE); // hide title bar
  214. }
  215. }
  216. }
  217. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement