Kaynağa Gözat

修复主页tab没有随着滑动的问题

zengjiebin 7 yıl önce
ebeveyn
işleme
2c337d3d4c

+ 13 - 13
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtSmallSheep.java

@@ -242,8 +242,7 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
     private TextView doIt;
     private TextView willStart;
     private TextView promote_goods_tv;
-    private View doItLine;
-    private FrameLayout lines;
+    private View do_it_every_day_line;
 
     /**
      * @return 是否显示兑换邀请码红包
@@ -483,13 +482,8 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
         doIt = titleCardLayout.findViewById(R.id.do_it_text);
         willStart = titleCardLayout.findViewById(R.id.will_start_text);
         promote_goods_tv = titleCardLayout.findViewById(R.id.promote_goods_tv);
-        doItLine = titleCardLayout.findViewById(R.id.do_it_every_day_line);
-        int lineWidth = (int) doIt.getPaint().measureText(doIt.getText().toString());
-        lines = titleCardLayout.findViewById(R.id.but_will_start);
-        LayoutParamsUtil.resetLayoutParams(lines, new Lp().setWidth(lineWidth));
-        int lineX = (G.WIDTH / 3 - lineWidth) / 2;
-        LayoutParamsUtil.resetLayoutParams(doItLine, new Lp().setWidth(G.WIDTH - lineX * 2));
-        lines.setX(lineX);
+        do_it_every_day_line = titleCardLayout.findViewById(R.id.do_it_every_day_line);
+        setTitleCardLayout(doIt.getText().toString(), 3, curPosition);
         doIt.setOnClickListener(v -> {
             if (mViewPager != null) {
                 mViewPager.setCurrentItem(0);
@@ -512,6 +506,12 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
         ViewUtil.setVisibility(titleCardLayout, false);
     }
 
+    private void setTitleCardLayout(String text, int n, int curPosition) {
+        int lineWidth = (int) doIt.getPaint().measureText(text);
+        int leftMargin = (G.WIDTH / n - lineWidth) / 2 + G.WIDTH * curPosition / n;
+        LayoutParamsUtil.resetLayoutParams(do_it_every_day_line, new Lp().setWidth(lineWidth).setLeftMargin(leftMargin));
+    }
+
     /**
      * 每日必做按钮事件回调
      */
@@ -522,7 +522,7 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
             TransitionManager.beginDelayedTransition(titleCardLayout, new ChangeBounds());
         }
-        LayoutParamsUtil.resetLayoutParams(doItLine, new Lp().setGravity(Gravity.START));
+        setTitleCardLayout(doIt.getText().toString(), 3, curPosition);
     }
 
     /**
@@ -535,7 +535,7 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
             TransitionManager.beginDelayedTransition(titleCardLayout, new ChangeBounds());
         }
-        LayoutParamsUtil.resetLayoutParams(doItLine, new Lp().setGravity(Gravity.CENTER));
+        setTitleCardLayout(doIt.getText().toString(), 3, curPosition);
     }
     /**
      * 点击限时抢购
@@ -547,7 +547,7 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
             TransitionManager.beginDelayedTransition(titleCardLayout, new ChangeBounds());
         }
-        LayoutParamsUtil.resetLayoutParams(doItLine, new Lp().setGravity(Gravity.END));
+        setTitleCardLayout(doIt.getText().toString(), 3, curPosition);
     }
 
     /**
@@ -650,6 +650,7 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
 
             @Override
             public void onPageSelected(int position) {
+                curPosition = position;
                 switch (position) {
                     case 0:
                         toDayClick();
@@ -661,7 +662,6 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
                         clickPromoteGoods();
                         break;
                 }
-                curPosition = position;
             }
 
             @Override

+ 8 - 28
app/src/main/res/layout/view_float_title_card.xml

@@ -4,14 +4,8 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical"
-    android:visibility="visible">
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="vertical"
-        android:background="@color/white"
-        android:paddingBottom="10dp">
+    android:background="@color/white"
+    android:paddingBottom="10dp">
 
         <LinearLayout
             android:layout_width="match_parent"
@@ -52,24 +46,10 @@
                 android:textSize="16sp" />
         </LinearLayout>
 
-        <FrameLayout
-            android:id="@+id/but_will_start"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content">
-
-            <View
-                android:id="@+id/do_it_every_day_line"
-                android:layout_width="70dp"
-                android:layout_height="2dp"
-                android:layout_gravity="start"
-                android:background="@color/blue_34a6e7" />
-
-            <!--<View-->
-            <!--android:id="@+id/will_start_line"-->
-            <!--android:layout_width="70dp"-->
-            <!--android:layout_height="2dp"-->
-            <!--android:background="@color/blue_34a6e7"-->
-            <!--android:visibility="invisible" />-->
-        </FrameLayout>
-    </LinearLayout>
+        <View
+            android:id="@+id/do_it_every_day_line"
+            android:layout_width="66dp"
+            android:layout_height="2dp"
+            android:layout_marginStart="36dp"
+            android:background="@color/blue_34a6e7" />
 </LinearLayout>