This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,292 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,94 @@ | ||
# segmentedview | ||
|
||
ios风格的分段控件,类似 UISegmentedControl | ||
|
||
![segmentedview](screenshot.png) | ||
|
||
## Gradle | ||
|
||
``` groovy | ||
repositories { | ||
maven { url "https://jitpack.io" } | ||
} | ||
``` | ||
|
||
``` groovy | ||
dependencies { | ||
compile 'com.github.czy1121:segmentedview:1.0.0' | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
**XML** | ||
|
||
``` xml | ||
<com.github.czy1121.view.SegmentedView | ||
android:id="@+id/sv1" | ||
android:layout_width="match_parent" | ||
android:layout_height="40dp" | ||
android:layout_marginBottom="10dp" | ||
app:svCornerRadius="10dp" | ||
app:svMainColor="#F44336" | ||
app:svStrokeWidth="1dp" | ||
app:svSubColor="#ffffff" | ||
app:svTexts="One|Two|Three|Four|Five|Six"/> | ||
``` | ||
|
||
**绑定事件** | ||
|
||
``` java | ||
|
||
((SegmentedView)findViewById(resId)).setOnItemSelectedListener(new SegmentedView.OnItemSelectedListener() { | ||
@Override | ||
public void onSelected(int index, String text) { | ||
Toast.makeText(this, index + " : " + text, Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
``` | ||
|
||
**属性** | ||
|
||
``` xml | ||
<declare-styleable name="SegmentedView"> | ||
<!-- 字体大小 --> | ||
<attr name="android:textSize" /> | ||
|
||
<!-- "|" 分隔的文本 --> | ||
<attr name="svTexts" format="string" /> | ||
<!-- 主色, 用于边框, 分隔线, 选中项的背景, 未选中项的文本 --> | ||
<attr name="svMainColor" format="color"/> | ||
<!-- 补色, 用于未选中项的背景, 选中项的文本, 默认 #ffffff --> | ||
<attr name="svSubColor" format="color"/> | ||
<!-- 边框, 分隔线 的宽度 --> | ||
<attr name="svStrokeWidth" format="dimension"/> | ||
<!-- 圆角大小 --> | ||
<attr name="svCornerRadius" format="dimension" /> | ||
<!-- item 左右的边距 --> | ||
<attr name="svHPadding" format="dimension"/> | ||
<!-- item 上下的边距 --> | ||
<attr name="svVPadding" format="dimension"/> | ||
</declare-styleable> | ||
``` | ||
|
||
## 参考 | ||
|
||
[SHSegmentControl](https://github.com/7heaven/SHSegmentControl) | ||
|
||
## License | ||
|
||
``` | ||
Copyright 2016 czy1121 | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
``` |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4"> | ||
<component name="FacetManager"> | ||
<facet type="android-gradle" name="Android-Gradle"> | ||
<configuration> | ||
<option name="GRADLE_PROJECT_PATH" value=":app" /> | ||
</configuration> | ||
</facet> | ||
<facet type="android" name="Android"> | ||
<configuration> | ||
<option name="SELECTED_BUILD_VARIANT" value="debug" /> | ||
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" /> | ||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" /> | ||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" /> | ||
<afterSyncTasks> | ||
<task>generateDebugSources</task> | ||
</afterSyncTasks> | ||
<option name="ALLOW_USER_CONFIGURATION" value="false" /> | ||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" /> | ||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" /> | ||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" /> | ||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" /> | ||
</configuration> | ||
</facet> | ||
</component> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false"> | ||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" /> | ||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" /> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/24.2.0/jars" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/24.2.0/jars" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-compat/24.2.0/jars" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-ui/24.2.0/jars" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-utils/24.2.0/jars" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-fragment/24.2.0/jars" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-media-compat/24.2.0/jars" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/24.2.0/jars" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/24.2.0/jars" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build/tmp" /> | ||
</content> | ||
<orderEntry type="jdk" jdkName="Android API 24 Platform" jdkType="Android SDK" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" exported="" name="support-media-compat-24.2.0" level="project" /> | ||
<orderEntry type="library" exported="" name="support-compat-24.2.0" level="project" /> | ||
<orderEntry type="library" exported="" name="support-v4-24.2.0" level="project" /> | ||
<orderEntry type="library" exported="" name="support-core-ui-24.2.0" level="project" /> | ||
<orderEntry type="library" exported="" name="support-core-utils-24.2.0" level="project" /> | ||
<orderEntry type="library" exported="" name="appcompat-v7-24.2.0" level="project" /> | ||
<orderEntry type="library" exported="" name="support-fragment-24.2.0" level="project" /> | ||
<orderEntry type="library" exported="" name="support-annotations-24.2.0" level="project" /> | ||
<orderEntry type="library" exported="" name="support-vector-drawable-24.2.0" level="project" /> | ||
<orderEntry type="library" exported="" name="animated-vector-drawable-24.2.0" level="project" /> | ||
<orderEntry type="module" module-name="library" exported="" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 24 | ||
buildToolsVersion "24.0.2" | ||
|
||
defaultConfig { | ||
applicationId "com.github.czy1121.segmentedview.example" | ||
minSdkVersion 16 | ||
targetSdkVersion 24 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile project(':library') | ||
compile 'com.android.support:appcompat-v7:24.2.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Volumes/data/cellar/android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.github.czy1121.segmentedview.demo" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name="com.github.czy1121.segmentedview.demo.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/github/czy1121/segmentedview/demo/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.czy1121.segmentedview.demo; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import com.github.czy1121.view.SegmentedView; | ||
|
||
public class MainActivity extends AppCompatActivity implements View.OnClickListener, SegmentedView.OnItemSelectedListener { | ||
|
||
|
||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
|
||
|
||
bind(R.id.sv1); | ||
bind(R.id.sv2); | ||
bind(R.id.sv3); | ||
bind(R.id.sv4); | ||
bind(R.id.sv5); | ||
bind(R.id.sv6); | ||
} | ||
|
||
void bind(int resId) { | ||
((SegmentedView)findViewById(resId)).setOnItemSelectedListener(this); | ||
} | ||
|
||
@Override | ||
public void onSelected(int index, String text) { | ||
Toast.makeText(this, index + " : " + text, Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
} | ||
} |
Oops, something went wrong.