Selaa lähdekoodia

[메인][New] 가로 스냅퍼 추가

hyodong.min 7 vuotta sitten
vanhempi
commit
5e01b8a631

+ 22 - 8
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainCategorySnapper.java

@@ -214,15 +214,8 @@ public class MainCategorySnapper extends RecyclerView.OnFlingListener {
     /**
      * 마지막 view (더보기)는 폭이 좁아서 포커스를 유지할 수 없기에 제외
      */
-    Log.w("APP# MainCategorySnapper | snapFromFling2", "|" + "targetChildPosition: " + targetChildPosition);
 
     View snapView = findSnapView(layoutManager);
-//    if (targetChildPosition < layoutManager.getChildCount() - 1) {
-//      snapView = findSnapView(layoutManager);
-//    }
-//    else {
-//      snapView = layoutManager.getChildAt(targetChildPosition);
-//    }
 
     Log.i("APP# MainCategorySnapper | snapToTargetExistingView", "|" + snapView);
 
@@ -380,7 +373,9 @@ public class MainCategorySnapper extends RecyclerView.OnFlingListener {
     }
     int absClosest = Integer.MAX_VALUE;
 
-    for (int i = 0; i < childCount; i++) {
+    int childMaxSize = 0;
+
+    for (int i = 0; i < childCount; ++i) {
       final View child = layoutManager.getChildAt(i);
       int childStart = helper.getDecoratedStart(child);
       int childEnd = helper.getDecoratedEnd(child);
@@ -393,6 +388,25 @@ public class MainCategorySnapper extends RecyclerView.OnFlingListener {
         absClosest = absDistance;
         closestChild = child;
       }
+
+      if (childMaxSize < childSize) {
+        childMaxSize = childSize;
+      }
+
+      /**
+       * 마지막이 기준 위치보다 왼쪽에 있으면 녀석을 타겟으로 본다.
+       * - 마지막 녀석은 크기가 작아서 그걸로 확인
+       */
+      if (childMaxSize > childSize) {
+        // padding start + childSize > lastChild.x
+//        Log.w("APP# MainCategorySnapper | findTopView", "|" + "padding: " + helper.getStartAfterPadding());
+//        Log.w("APP# MainCategorySnapper | findTopView", "|" + "childMaxSize: " + childMaxSize);
+//        Log.w("APP# MainCategorySnapper | findTopView", "|" + "snapOffset: " + snapOffset);
+//        Log.w("APP# MainCategorySnapper | findTopView", "|" + "child.x: " + child.getX());
+        if (childMaxSize > child.getX()) {
+          closestChild = child;
+        }
+      }
     }
     return closestChild;
   }

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainFragment.java

@@ -61,7 +61,7 @@ public class MainFragment extends FragmentBase<MainPresenter> implements IMainVi
     contentsRecyclerView = findViewById(R.id.recycler_view_main);
 
     if (contentsRecyclerView.getOnFlingListener() == null) {
-      MainContentsSnapper snapper = new MainContentsSnapper(1000, -ResourceUtil.dpToPx(25));
+      MainContentsSnapper snapper = new MainContentsSnapper(1000, ResourceUtil.getStatusBarHeight() - ResourceUtil.dpToPx(25));
       snapper.attachToRecyclerView(contentsRecyclerView);
     }
 

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

@@ -4,7 +4,7 @@
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="wrap_content"
-  android:layout_height="match_parent"
+  android:layout_height="@dimen/main_contents_image_height"
   android:paddingStart="1dp"
   android:paddingEnd="11dp">
   <!--