Browse Source

添加空布局

niusongtao@dl-cg.com 5 years ago
parent
commit
4409f0a915

+ 67 - 0
base_library/src/main/java/com/mgtech/base_library/custom/EmptyView.java

@@ -0,0 +1,67 @@
+package com.mgtech.base_library.custom;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import androidx.annotation.DrawableRes;
+import androidx.constraintlayout.widget.ConstraintLayout;
+
+import com.mgtech.base_library.R;
+
+/**
+ * @ProjectName: BaseLibrary
+ * @Package: com.mgtech.base_library.custom
+ * @ClassName: EmptyView
+ * @Description: 空布局
+ * @Author: niusongtao
+ * @CreateDate: 2020/8/18 11:00
+ * @UpdateUser: 更新者:niusongtao
+ * @UpdateDate: 2020/8/18 11:00
+ * @UpdateRemark: 更新说明:
+ * @Version: 1.0
+ */
+public class EmptyView extends ConstraintLayout {
+    private ImageView emptyImage;
+    private TextView emptyText;
+
+    public EmptyView(Context context) {
+        super(context);
+        initView(context);
+    }
+
+    public EmptyView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        initView(context);
+        setView(context, attrs);
+    }
+
+    public EmptyView(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+    }
+
+    private void initView(Context context){
+        LayoutInflater.from(context).inflate(R.layout.layout_empty_view,this);
+        emptyImage = findViewById(R.id.empty_image);
+        emptyText = findViewById(R.id.empty_text);
+    }
+
+    private void setView(Context context, AttributeSet attrs){
+        TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.EmptyView);
+        emptyImage.setBackgroundResource(typedArray.getResourceId(R.styleable.EmptyView_empty_image,0));
+        emptyText.setText(typedArray.getString(R.styleable.EmptyView_empty_text));
+        emptyText.setTextColor(typedArray.getColor(R.styleable.EmptyView_empty_text_color,context.getColor(R.color.black_alpha_50)));
+        typedArray.recycle();
+    }
+
+    public void setEmptyImage(@DrawableRes int image){
+        emptyImage.setBackgroundResource(image);
+    }
+
+    public void setEmptyText(String text){
+        emptyText.setText(text);
+    }
+}

+ 2 - 2
base_library/src/main/java/com/mgtech/base_library/http/common/HttpConfig.java

@@ -16,8 +16,8 @@ public class HttpConfig {
     public static final long HTTP_TIME = 30;
 
 //    public static final String BASE_URL = "http://172.14.1.61:9400/"; //测试
-    public static final String BASE_URL = "http://api.basss.pj.dl-cg.com/";//大连环境
-//    public static final String BASE_URL = "https://api.d.ulestyle.com/";//上海
+//    public static final String BASE_URL = "http://api.basss.pj.dl-cg.com/";//大连环境
+    public static final String BASE_URL = "https://api.d.ulestyle.com/";//上海
 //    public static final String BASE_URL = "http://172.14.3.33:9400/";//本地
 
 //        public static final String BASE_URL = "http://172.14.3.96:8310/";//孙 本地

+ 31 - 0
base_library/src/main/res/layout/layout_empty_view.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<merge xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
+
+    <ImageView
+        android:id="@+id/empty_image"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        app:layout_constraintBottom_toTopOf="@id/empty_text"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintVertical_chainStyle="packed" />
+
+    <TextView
+        android:id="@+id/empty_text"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="@dimen/dp_10"
+        android:textColor="@color/black_alpha_50"
+        android:textSize="@dimen/sp_14"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="@id/empty_image"
+        app:layout_constraintStart_toStartOf="@id/empty_image"
+        app:layout_constraintTop_toBottomOf="@id/empty_image" />
+
+</merge>

+ 6 - 0
base_library/src/main/res/values/attrs.xml

@@ -127,4 +127,10 @@
         <attr name="clear_image" format="reference"/>
     </declare-styleable>
 
+    <declare-styleable name="EmptyView">
+        <attr name="empty_image" format="reference"/>
+        <attr name="empty_text" format="string"/>
+        <attr name="empty_text_color" format="color"/>
+    </declare-styleable>
+
 </resources>