Sfoglia il codice sorgente

[공통][Bug] 반투명 액션바 적용

hyodong.min 7 anni fa
parent
commit
015109a71d

+ 7 - 13
app/src/main/java/kr/co/zumo/app/lifeplus/manager/ActionBarManager.java

@@ -20,7 +20,6 @@ import java.util.HashMap;
 import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.util.ResourceUtil;
 import kr.co.zumo.app.lifeplus.view.CustomHeaderBehavior;
-import kr.co.zumo.app.lifeplus.view.CustomScrollingViewBehavior;
 
 /**
  * ActionBar 관리
@@ -214,14 +213,12 @@ public class ActionBarManager {
     AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
     CoordinatorLayout.LayoutParams appBarLayoutParams = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
     if (isEnabled) {
-      params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL);
+      params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
       appBarLayoutParams.setBehavior(new AppBarLayout.Behavior());
-      appBarLayout.setLayoutParams(appBarLayoutParams);
     }
     else {
       params.setScrollFlags(0);
       appBarLayoutParams.setBehavior(null);
-      appBarLayout.setLayoutParams(appBarLayoutParams);
     }
   }
 
@@ -236,41 +233,38 @@ public class ActionBarManager {
       containerLayoutParams.setBehavior(null);
       containerLayoutParams.topMargin = 0;
       containerLayoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
-      container.setLayoutParams(containerLayoutParams);
     }
     else if (isTransparentBackground) {
       if (isScrollable) {
         // todo 스크롤되는 경우에는 appbar behavior 도 수정 필요;
         AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
+        params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
         CoordinatorLayout.LayoutParams appBarLayoutParams = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
-        params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL);
         appBarLayoutParams.setBehavior(new CustomHeaderBehavior());
-        appBarLayout.setLayoutParams(appBarLayoutParams);
 
         // todo 스크롤되는 경우에는 appbar behavior 도 수정 필요;
         containerLayoutParams.setBehavior(null);
         containerLayoutParams.topMargin = 0;
         containerLayoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
-        container.setLayoutParams(containerLayoutParams);
       }
       else {
         containerLayoutParams.setBehavior(null);
         containerLayoutParams.topMargin = 0;
         containerLayoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
-        container.setLayoutParams(containerLayoutParams);
       }
     }
     else {
       if (isScrollable) {
+        CoordinatorLayout.LayoutParams appBarLayoutParams = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
+        appBarLayoutParams.setBehavior(new CustomHeaderBehavior());
+        containerLayoutParams.setBehavior(null);
         containerLayoutParams.topMargin = 0;
-        containerLayoutParams.setBehavior(new CustomScrollingViewBehavior());
-        container.setLayoutParams(containerLayoutParams);
+        containerLayoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
       }
       else {
         containerLayoutParams.setBehavior(null);
         containerLayoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
         containerLayoutParams.topMargin = ResourceUtil.getDimension(R.dimen.action_bar_height);
-        container.setLayoutParams(containerLayoutParams);
       }
     }
   }
@@ -363,7 +357,7 @@ public class ActionBarManager {
   }
 
   private void setBackgroundTransparent(boolean isTransparent) {
-    toolbar.setBackgroundResource(isTransparent ? android.R.color.transparent : R.color.CFFFFFF);
+    toolbar.setBackgroundResource(isTransparent ? android.R.color.transparent : R.color.C80FFFFFF);
   }
 
   /**

+ 3 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/CustomHeaderBehavior.java

@@ -24,6 +24,9 @@ public class CustomHeaderBehavior extends AppBarLayout.Behavior {
   public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dx, int dy, int[] consumed, int type) {
     super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
 
+    /**
+     * appbarlayout 이 스크롤되는 동안에도 consume 은 하지 않아 nested scroller 도 함께 스크롤된다.
+     */
     consumed[1] = 0;
   }
 

+ 1 - 1
app/src/main/res/layout/action_bar.xml

@@ -6,7 +6,7 @@
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_gravity="fill_horizontal"
-  android:background="@android:color/transparent"
+  android:background="@null"
   tools:layout_height="100dp">
 
   <android.support.constraint.ConstraintLayout

+ 1 - 1
app/src/main/res/layout/activity_main.xml

@@ -22,7 +22,7 @@
     android:id="@+id/layout_app_bar"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:background="@android:color/transparent"
+    android:background="@null"
     app:elevation="0dp"
     >
 

+ 1 - 0
app/src/main/res/layout/fragment_my_main.xml

@@ -8,6 +8,7 @@
   android:orientation="vertical">
 
   <android.support.constraint.ConstraintLayout
+    android:paddingTop="@dimen/action_bar_height"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
 

+ 1 - 1
app/src/main/res/layout/main_contents_weather.xml

@@ -4,7 +4,7 @@
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
-  android:layout_height="216dp"
+  android:layout_height="274dp"
   android:background="@color/CFFFFFF"
   android:orientation="vertical"
   android:paddingTop="@dimen/main_contents_weather_marget_top">

+ 1 - 0
app/src/main/res/values/colors.xml

@@ -5,6 +5,7 @@
   <color name="colorAccent">#FF4081</color>
   <color name="CCCCCCC">#CCCCCC</color>
   <color name="CFFFFFF">#FFFFFF</color>
+  <color name="C80FFFFFF">#80FFFFFF</color> <!-- 50% -->
   <color name="C000000">#000000</color>
   <!--opacity 40%-->
   <color name="C66000000">#66000000</color>

+ 1 - 1
app/src/main/res/values/dimens.xml

@@ -4,7 +4,7 @@
   <dimen name="activity_vertical_margin">16dp</dimen>
   <dimen name="fab_margin">22dp</dimen>
   <dimen name="action_bar_height">58dp</dimen>
-  <dimen name="main_contents_weather_marget_top">38dp</dimen>  <!--38dp-->
+  <dimen name="main_contents_weather_marget_top">96dp</dimen>  <!--38dp + 58dp-->
   <dimen name="main_contents_start_gap">57dp</dimen>
   <dimen name="main_contents_image_width">285dp</dimen>
   <dimen name="main_contents_image_height">328dp</dimen>