Просмотр исходного кода

配合美工调整发现模块界面

zengjiebin лет назад: 7
Родитель
Сommit
d9dc7e43be

+ 63 - 0
app/src/main/java/com/kfzs/duanduan/fragment/FgtFind.java

@@ -4,6 +4,9 @@ import android.app.Activity;
 import android.os.Bundle;
 import android.support.design.widget.TabLayout;
 import android.support.v4.view.ViewPager;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
 
 import com.alibaba.fastjson.JSON;
 import com.kfzs.duanduan.BaseCompatFragment;
@@ -17,6 +20,7 @@ import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
 
+import java.lang.reflect.Field;
 import java.util.List;
 
 import butterknife.BindView;
@@ -96,6 +100,65 @@ public class FgtFind extends BaseCompatFragment {
             }
         });
         pager.setCurrentItem(position);
+        reflex(indicator);
     }
     private int position = 0;//默认选中第一个
+
+    /**
+     * 通过反射调整tabLayout中下划线的宽度
+     * @param tabLayout
+     */
+    public void reflex(final TabLayout tabLayout){
+        //了解源码得知 线的宽度是根据 tabView的宽度来设置的
+        tabLayout.post(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    //拿到tabLayout的mTabStrip属性
+                    LinearLayout mTabStrip = (LinearLayout) tabLayout.getChildAt(0);
+
+//                    int dp10 = dip2px(tabLayout.getContext(), 10);
+                    int add = getResources().getDimensionPixelSize(R.dimen.content_padding_10);
+                    int count = mTabStrip.getChildCount();
+                    for (int i = 0; i < count; i++) {
+                        View tabView = mTabStrip.getChildAt(i);
+
+                        //拿到tabView的mTextView属性  tab的字数不固定一定用反射取mTextView
+                        Field mTextViewField = tabView.getClass().getDeclaredField("mTextView");
+                        mTextViewField.setAccessible(true);
+
+                        TextView mTextView = (TextView) mTextViewField.get(tabView);
+
+                        tabView.setPadding(0, 0, 0, 0);
+
+                        //因为我想要的效果是   字多宽线就多宽,所以测量mTextView的宽度
+                        int width = 0;
+                        width = mTextView.getWidth();
+                        if (width == 0) {
+                            mTextView.measure(0, 0);
+                            width = mTextView.getMeasuredWidth();
+                        }
+
+                        //设置tab左右间距为10dp  注意这里不能使用Padding 因为源码中线的宽度是根据 tabView的宽度来设置的
+                        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tabView.getLayoutParams();
+                        params.width = width ;
+                        int margin = (G.WIDTH - 5*width - 2*add) / 10;
+                        params.leftMargin = margin + (i == 0 ? add : 0);
+                        params.rightMargin = margin + (i + 1 == count ? add : 0);
+                        tabView.setLayoutParams(params);
+
+                        tabView.invalidate();
+                    }
+
+                } catch (NoSuchFieldException e) {
+                    e.printStackTrace();
+                } catch (IllegalAccessException e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+
+    }
+
+
 }

+ 9 - 5
app/src/main/res/layout/fgt_find.xml

@@ -14,18 +14,22 @@
         android:padding="@dimen/dp_10"
         android:text="@string/main_tab_find"
         android:textColor="@color/black"
-        android:textSize="15sp" />
+        android:textSize="18sp" />
 
     <android.support.design.widget.TabLayout
         android:id="@+id/indicator"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        app:tabGravity="fill"
+        app:tabBackground="@android:color/transparent"
+        app:tabIndicatorHeight="4dp"
+        app:tabGravity="center"
         app:tabIndicatorColor="#4bc1fe"
-        app:tabMode="fixed"
+        app:tabPadding="7dp"
+        app:tabMode="scrollable"
         app:tabSelectedTextColor="#4bc1fe"
-        app:tabTextAppearance="@android:style/TextAppearance.Holo.Medium"
-        app:tabTextColor="#444444" />
+        app:tabTextColor="#444444"
+        app:tabTextAppearance="@style/SheepTabLayoutTextAppearance"
+        />
 
     <android.support.v4.view.ViewPager
         android:id="@+id/pager"

+ 16 - 13
app/src/main/res/layout/find_item.xml

@@ -2,12 +2,16 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_marginEnd="@dimen/content_padding"
     android:layout_marginStart="@dimen/content_padding"
-    android:layout_marginTop="@dimen/content_padding_10"
+    android:layout_marginTop="@dimen/content_padding"
     android:background="@drawable/x_shap_shadow_bg_rectgangle_white"
     android:orientation="vertical"
-    android:padding="@dimen/dp_10">
+    android:paddingTop="14dp"
+    android:paddingStart="@dimen/content_padding"
+    android:paddingEnd="@dimen/content_padding"
+    android:paddingBottom="15dp">
 
     <LinearLayout
         android:layout_width="match_parent"
@@ -35,10 +39,10 @@
         android:id="@+id/find_item_time"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginTop="@dimen/dp_10"
+        android:layout_marginTop="5dp"
         android:text="@string/app_name"
         android:textColor="#9B9B9B"
-        android:textSize="12sp" />
+        android:textSize="11sp" />
 
 
     <ImageView
@@ -50,7 +54,7 @@
         android:adjustViewBounds="true"
         android:src="@mipmap/icon" />
 
-    <RelativeLayout
+    <android.support.constraint.ConstraintLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
 
@@ -58,7 +62,8 @@
             android:id="@+id/find_item_des"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginTop="@dimen/dp_10"
+            android:layout_marginTop="@dimen/content_padding"
+            app:layout_constraintTop_toTopOf="parent"
             android:maxLines="2"
             android:ellipsize="end"
             android:text="@string/app_name"
@@ -69,8 +74,8 @@
             android:id="@+id/find_item_pf_label"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_below="@+id/find_item_des"
-            android:layout_marginTop="@dimen/dp_10"
+            app:layout_constraintTop_toBottomOf="@+id/find_item_des"
+            android:layout_marginTop="8dp"
             android:text="评分:8.9"
             android:textColor="#646464"
             android:textSize="14sp" />
@@ -78,11 +83,9 @@
         <TextView
             android:id="@+id/find_item_download"
             style="@style/style_button_find"
-            android:layout_alignParentEnd="true"
-            android:layout_marginTop="@dimen/content_padding_5"
-            android:layout_below="@+id/find_item_des"
-            android:layout_centerVertical="true"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintBottom_toBottomOf="@+id/find_item_pf_label"
             android:text="下载游戏" />
-    </RelativeLayout>
+    </android.support.constraint.ConstraintLayout>
 
 </LinearLayout>

+ 6 - 6
app/src/main/res/layout/find_item_tag.xml

@@ -3,14 +3,14 @@
     android:id="@+id/find_tag_tv"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
-    android:paddingTop="5dp"
-    android:paddingBottom="5dp"
-    android:paddingStart="20dp"
-    android:paddingEnd="20dp"
+    android:paddingTop="2dp"
+    android:paddingBottom="2dp"
+    android:paddingStart="10dp"
+    android:paddingEnd="10dp"
     android:gravity="center"
     android:textAlignment="center"
     android:textColor="@color/main_tab_activated"
-    android:background="@drawable/layer_list_check_rectgangle"
+    android:background="@drawable/btn_main_stroke_click"
     android:layout_marginStart="@dimen/dp_10"
-    android:textSize="@dimen/text_size_13"
+    android:textSize="11sp"
     android:text="小标签" />

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

@@ -23,7 +23,7 @@
         android:gravity="center"
         android:text="@string/app_name"
         android:textColor="@color/black_text_deep"
-        android:textSize="@dimen/text_size_4"/>
+        android:textSize="18sp"/>
 
     <!--右边按钮-->
 

+ 4 - 0
app/src/main/res/values/dd_styles.xml

@@ -306,4 +306,8 @@
         <item name="android:layout_marginEnd">@dimen/content_padding_20</item>
         <item name="android:background">#DFDFDF</item>
     </style>
+    <style name="SheepTabLayoutTextAppearance" parent="@android:style/TextAppearance.Holo.Large">
+        <item name="android:textSize">15sp</item>
+        <item name="android:textColor">#444444</item>
+    </style>
 </resources>