浏览代码

CommonUserItemView.java 修改

niusongtao@dl-cg.com 5 年之前
父节点
当前提交
5d860e6567

+ 16 - 0
base_library/src/main/java/com/mgtech/base_library/custom/CommonUserItemView.java

@@ -7,12 +7,14 @@ import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.util.TypedValue;
 import android.view.View;
+import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.TextView;
 
 import androidx.annotation.ColorInt;
 import androidx.constraintlayout.widget.ConstraintLayout;
 import androidx.constraintlayout.widget.ConstraintSet;
+import androidx.core.content.ContextCompat;
 
 import com.mgtech.base_library.R;
 
@@ -116,8 +118,22 @@ public class CommonUserItemView extends ConstraintLayout {
             set.applyTo(this);
         }
 
+        lineView.setBackgroundColor(typedArray.getColor(R.styleable.CommonUserItemView_item_line_bg
+                , ContextCompat.getColor(context,R.color.f7f7f7)));
         lineView.setVisibility(typedArray.getBoolean(R.styleable.CommonUserItemView_item_line_show,true)
                 ?VISIBLE:GONE);
+
+        int lineStart = typedArray.getDimensionPixelSize(R.styleable.CommonUserItemView_item_line_margin_start,0);
+        int lineEnd = typedArray.getDimensionPixelSize(R.styleable.CommonUserItemView_item_line_margin_end,0);
+        LayoutParams lineLayoutParams = (LayoutParams) lineView.getLayoutParams();
+        lineLayoutParams.setMargins(lineStart,0,lineEnd,0);
+        lineView.setLayoutParams(lineLayoutParams);
+
+        int top = typedArray.getDimensionPixelSize(R.styleable.CommonUserItemView_item_padding_top,0);
+        int bottom = typedArray.getDimensionPixelSize(R.styleable.CommonUserItemView_item_padding_bottom,0);
+        LayoutParams layoutParams = (LayoutParams) titleText.getLayoutParams();
+        layoutParams.setMargins(0,top,0,bottom);
+        titleText.setLayoutParams(layoutParams);
         typedArray.recycle();
     }
 

+ 3 - 2
base_library/src/main/res/layout/layout_common_user_item.xml

@@ -54,9 +54,10 @@
 
     <View
         android:id="@+id/item_line"
-        android:layout_width="match_parent"
+        android:layout_width="@dimen/dp_0"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
         android:layout_height="@dimen/dp_1"
-        android:background="@color/bg_color"
         app:layout_constraintBottom_toBottomOf="parent" />
 
 </merge>

+ 5 - 1
base_library/src/main/res/values/attrs.xml

@@ -78,7 +78,7 @@
     <declare-styleable name="CommonUserItemView">
         <attr name="item_left_image_bg" format="reference"/>
         <attr name="item_right_image_bg" format="reference"/>
-        <attr name="item_line_bg" format="reference"/>
+        <attr name="item_line_bg" format="color"/>
         <attr name="item_left_image_show" format="boolean"/>
         <attr name="item_right_image_show" format="boolean"/>
         <attr name="item_line_show" format="boolean"/>
@@ -91,6 +91,10 @@
         <attr name="item_detail_text_size" format="dimension"/>
         <attr name="item_detail_text_drawable" format="reference"/>
         <attr name="item_detail_text_drawable_padding" format="dimension"/>
+        <attr name="item_padding_top" format="dimension"/>
+        <attr name="item_padding_bottom" format="dimension"/>
+        <attr name="item_line_margin_start" format="dimension"/>
+        <attr name="item_line_margin_end" format="dimension"/>
         <attr name="item_detail_text_style">
             <flag name="normal" value="10" />
             <flag name="bold" value="20" />

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

@@ -55,6 +55,7 @@
     <color name="all_yellow">#FFD700</color>
     <color name="f2f2f2">#F2F2F2</color>
     <color name="_787878">#787878</color>
+    <color name="f7f7f7">#f7f7f7</color>
 
 
     <color name="biometricprompt_color_primary">#415FFF</color>