diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..1ebdb32
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,251 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+ ^$
+
+
+
+
+
+
+
+
+ style
+ ^$
+
+
+
+
+
+
+
+
+ .*
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:layout_width
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:layout_height
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:layout_.*
+ http://schemas.android.com/apk/res/android
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:width
+ http://schemas.android.com/apk/res/android
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:height
+ http://schemas.android.com/apk/res/android
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+ http://schemas.android.com/apk/res/android
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..aaba541
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..32fb988
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..7546a2d
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
new file mode 100644
index 0000000..7f68460
--- /dev/null
+++ b/.idea/runConfigurations.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index e3ba470..128683e 100644
--- a/README.md
+++ b/README.md
@@ -130,6 +130,15 @@ labelsView.setOnLabelSelectChangeListener(new LabelsView.OnLabelSelectChangeList
//label是被选中的标签,data是标签所对应的数据,isSelect是是否选中,position是标签的位置。
}
});
+
+//『+添加标签』的点击监听
+ labelsView.setAddTextViewListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ label.add("测试");
+ labelsView.setLabels(label);
+ }
+ });
```
**5、常用方法**
@@ -179,7 +188,11 @@ public void setLineMargin(int margin);
//设置标签的间隔
public void setWordMargin(int margin);
+
+//尾部添加『+添加标签』项
+public void setAddLabel(boolean visible)
```
+
所有的set方法都有对应的get方法,这里就不说了。
### 效果图:
diff --git a/app/build.gradle b/app/build.gradle
index 07a39e1..2c8d81d 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 23
- buildToolsVersion "23.0.3"
+ compileSdkVersion 26
+ buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.donkingliang.labelsviewdemo"
- minSdkVersion 9
- targetSdkVersion 23
+ minSdkVersion 14
+ targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -20,12 +20,12 @@ android {
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
- compile 'com.android.support:appcompat-v7:23.4.0'
- testCompile 'junit:junit:4.12'
+ implementation 'com.android.support:appcompat-v7:26.1.0'
+ testImplementation 'junit:junit:4.12'
- compile project(":labels")
+ implementation project(":labels")
}
diff --git a/app/src/main/java/com/donkingliang/labelsviewdemo/MainActivity.java b/app/src/main/java/com/donkingliang/labelsviewdemo/MainActivity.java
index 0275ded..8e2536a 100644
--- a/app/src/main/java/com/donkingliang/labelsviewdemo/MainActivity.java
+++ b/app/src/main/java/com/donkingliang/labelsviewdemo/MainActivity.java
@@ -2,7 +2,6 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
-import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
@@ -10,7 +9,6 @@
import com.donkingliang.labels.LabelsView;
import java.util.ArrayList;
-import java.util.List;
import static com.donkingliang.labelsviewdemo.R.id.labels;
@@ -26,40 +24,48 @@ protected void onCreate(Bundle savedInstanceState) {
labelsView = (LabelsView) findViewById(labels);
//测试的数据
-// ArrayList label = new ArrayList<>();
-// label.add("Android");
-// label.add("IOS");
-// label.add("前端");
-// label.add("后台");
-// label.add("微信开发");
-// label.add("游戏开发");
-// label.add("Java");
-// label.add("JavaScript");
-// label.add("C++");
-// label.add("PHP");
-// label.add("Python");
-// label.add("Swift");
-// labelsView.setLabels(label);
-
- ArrayList testList = new ArrayList<>();
- testList.add(new TestBean("Android",1));
- testList.add(new TestBean("IOS",2));
- testList.add(new TestBean("前端",3));
- testList.add(new TestBean("后台",4));
- testList.add(new TestBean("微信开发",5));
- testList.add(new TestBean("游戏开发",6));
- testList.add(new TestBean("Java",7));
- testList.add(new TestBean("JavaScript",8));
- testList.add(new TestBean("C++",9));
- testList.add(new TestBean("PHP",10));
- testList.add(new TestBean("Python",11));
- testList.add(new TestBean("Swift",12));
- labelsView.setLabels(testList, new LabelsView.LabelTextProvider() {
+ final ArrayList label = new ArrayList<>();
+ label.add("Android");
+ label.add("IOS");
+ label.add("前端");
+ label.add("后台");
+ label.add("微信开发");
+ label.add("游戏开发");
+ label.add("Java");
+ label.add("JavaScript");
+ label.add("C++");
+ label.add("PHP");
+ label.add("Python");
+ label.add("Swift");
+ labelsView.setSelectType(LabelsView.SelectType.NONE);
+ labelsView.setAddTextViewListener(new View.OnClickListener() {
@Override
- public CharSequence getLabelText(TextView label, int position, TestBean data) {
- return data.getName();
+ public void onClick(View v) {
+ label.add("测试");
+ labelsView.setLabels(label);
}
});
+ labelsView.setLabels(label);
+
+// final ArrayList testList = new ArrayList<>();
+// testList.add(new TestBean("Android",1));
+// testList.add(new TestBean("IOS",2));
+// testList.add(new TestBean("前端",3));
+// testList.add(new TestBean("后台",4));
+// testList.add(new TestBean("微信开发",5));
+// testList.add(new TestBean("游戏开发",6));
+// testList.add(new TestBean("Java",7));
+// testList.add(new TestBean("JavaScript",8));
+// testList.add(new TestBean("C++",9));
+// testList.add(new TestBean("PHP",10));
+// testList.add(new TestBean("Python",11));
+// testList.add(new TestBean("Swift",12));
+// labelsView.setLabels(testList, new LabelsView.LabelTextProvider() {
+// @Override
+// public CharSequence getLabelText(TextView label, int position, TestBean data) {
+// return data.getName();
+// }
+// });
findViewById(R.id.btn_none).setOnClickListener(this);
findViewById(R.id.btn_single).setOnClickListener(this);
diff --git a/app/src/main/res/drawable/label_bg.xml b/app/src/main/res/drawable/label_bg.xml
index fddde7c..49f55e5 100644
--- a/app/src/main/res/drawable/label_bg.xml
+++ b/app/src/main/res/drawable/label_bg.xml
@@ -1,19 +1,26 @@
-
- -
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+ -
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/label_text_color.xml b/app/src/main/res/drawable/label_text_color.xml
index 1d45234..d4c4037 100644
--- a/app/src/main/res/drawable/label_text_color.xml
+++ b/app/src/main/res/drawable/label_text_color.xml
@@ -2,6 +2,7 @@
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 169c8d2..d5f2a7a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,11 +3,11 @@
buildscript {
repositories {
jcenter()
+ google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.1.0'
- classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
-
+ classpath 'com.android.tools.build:gradle:3.1.3'
+ classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
@@ -16,6 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
+ google()
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 122a0dc..d9cc84c 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Mon Dec 28 10:00:20 PST 2015
+#Thu Jul 05 21:36:34 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
diff --git a/labels/build.gradle b/labels/build.gradle
index b3c64c6..4dde13a 100644
--- a/labels/build.gradle
+++ b/labels/build.gradle
@@ -4,12 +4,12 @@ apply plugin: 'com.github.dcendents.android-maven'
group='com.github.donkingliang' // 指定group,com.github.<用户名>
android {
- compileSdkVersion 23
- buildToolsVersion "23.0.3"
+ compileSdkVersion 26
+ buildToolsVersion '27.0.3'
defaultConfig {
- minSdkVersion 9
- targetSdkVersion 23
+ minSdkVersion 14
+ targetSdkVersion 26
versionCode 1
versionName "1.0"
}
@@ -22,9 +22,9 @@ android {
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- testCompile 'junit:junit:4.12'
- compile 'com.android.support:appcompat-v7:23.4.0'
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ testImplementation 'junit:junit:4.12'
+ implementation 'com.android.support:appcompat-v7:26.1.0'
}
//---------------------------------------------
diff --git a/labels/src/main/java/com/donkingliang/labels/LabelsView.java b/labels/src/main/java/com/donkingliang/labels/LabelsView.java
index 9cd4b59..a594da6 100644
--- a/labels/src/main/java/com/donkingliang/labels/LabelsView.java
+++ b/labels/src/main/java/com/donkingliang/labels/LabelsView.java
@@ -18,851 +18,843 @@
public class LabelsView extends ViewGroup implements View.OnClickListener {
- private Context mContext;
-
- private ColorStateList mTextColor;
- private float mTextSize;
- private Drawable mLabelBg;
- private int mTextPaddingLeft;
- private int mTextPaddingTop;
- private int mTextPaddingRight;
- private int mTextPaddingBottom;
- private int mWordMargin;
- private int mLineMargin;
- private SelectType mSelectType;
- private int mMaxSelect;
-
- //用于保存label数据的key
- private static final int KEY_DATA = R.id.tag_key_data;
- //用于保存label位置的key
- private static final int KEY_POSITION = R.id.tag_key_position;
-
- private ArrayList