├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── czm │ │ │ └── xctextview │ │ │ ├── MainActivity.kt │ │ │ └── XCJustifyTextView.kt │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── czm │ │ │ └── xctextview │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── czm │ │ └── xctextview │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro ├── build.gradle └── app.iml ├── README.md ├── settings.gradle ├── xctextview.jpeg ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── local.properties ├── XCJustifyTextView.iml ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XCJustifyTextview 2 | Android仿微信读书文本两端左右对齐控件 3 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name='XCJustifyTextView' 2 | include ':app' 3 | -------------------------------------------------------------------------------- /xctextview.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jczmdeveloper/XCJustifyTextview/HEAD/xctextview.jpeg -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | XCJustifyTextView 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jczmdeveloper/XCJustifyTextview/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jczmdeveloper/XCJustifyTextview/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jczmdeveloper/XCJustifyTextview/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jczmdeveloper/XCJustifyTextview/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jczmdeveloper/XCJustifyTextview/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jczmdeveloper/XCJustifyTextview/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jczmdeveloper/XCJustifyTextview/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jczmdeveloper/XCJustifyTextview/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jczmdeveloper/XCJustifyTextview/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jczmdeveloper/XCJustifyTextview/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jczmdeveloper/XCJustifyTextview/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #6200EE 4 | #3700B3 5 | #03DAC5 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Apr 26 12:47:57 CST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/czm/xctextview/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.czm.xctextview 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file is automatically generated by Android Studio. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file should *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | # 7 | # Location of the SDK. This is only used by Gradle. 8 | # For customization when using a Version Control System, please read the 9 | # header note. 10 | sdk.dir=/Users/caizhiming/Library/Android/sdk 11 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/czm/xctextview/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.czm.xctextview 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.czm.xctextview", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /XCJustifyTextView.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 28 7 | 8 | 9 | defaultConfig { 10 | applicationId "com.czm.xctextview" 11 | minSdkVersion 23 12 | targetSdkVersion 28 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 31 | implementation 'androidx.appcompat:appcompat:1.1.0' 32 | implementation 'androidx.core:core-ktx:1.2.0' 33 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 34 | testImplementation 'junit:junit:4.12' 35 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 23 | 24 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/czm/xctextview/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.czm.xctextview 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import kotlinx.android.synthetic.main.activity_main.* 6 | 7 | 8 | class MainActivity : AppCompatActivity() { 9 | private val text = "Hooray! It's snowing! It's time to make a snowman.James runs out. He makes a big pile of snow. He puts a big snowball on top. He adds a scarf and a hat. He adds an orange for the nose. He adds coal for the eyes and buttons.In the evening, James opens the door. What does he see? The snowman is moving! James invites him in. The snowman has never been inside a house. He says hello to the cat. He plays with paper towels.A moment later, the snowman takes James's hand and goes out.They go up, up, up into the air! They are flying! What a wonderful night!The next morning, James jumps out of bed. He runs to the door.He wants to thank the snowman. But he's gone." 10 | private val text1 = "AppCompatActivity AppCompatActivityActivityActivityActivity" 11 | private val text2 = "For every layout expression, there is a binding adapter that makes the framework calls required to set the corresponding properties or listeners. For example, the binding adapter can take care of calling the setText() method to set the text property or call the setOnClickListener() method to add a listener to the click event. The most common binding adapters, such as the adapters for the android:text property used in the examples in this page, are available for you to use in the android.databinding.adapters package. For a list of the common binding adapters, see adapters. You can also create custom adapters, as shown in the following example:" 12 | 13 | override fun onCreate(savedInstanceState: Bundle?) { 14 | super.onCreate(savedInstanceState) 15 | setContentView(R.layout.activity_main) 16 | just.text = text2 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/java/com/czm/xctextview/XCJustifyTextView.kt: -------------------------------------------------------------------------------- 1 | package com.czm.xctextview 2 | 3 | import android.content.Context 4 | import android.graphics.Canvas 5 | import android.text.StaticLayout 6 | import android.text.TextPaint 7 | import android.text.TextUtils 8 | import android.util.AttributeSet 9 | import android.util.Log 10 | import android.view.Gravity 11 | import android.view.View 12 | import androidx.appcompat.widget.AppCompatTextView 13 | import java.io.UnsupportedEncodingException 14 | import java.util.* 15 | 16 | /** 17 | * Description: 自定义两端左右对齐的TextView,中英文排版效果 18 | * 非中文单词换行截断 19 | */ 20 | class XCJustifyTextView @JvmOverloads constructor( 21 | context: Context?, 22 | attrs: AttributeSet? = null, 23 | defStyleAttr: Int = 0 24 | ) : AppCompatTextView(context, attrs, defStyleAttr) { 25 | /** 26 | * 绘制文字的起始Y坐标 27 | */ 28 | private var mLineY = 0f 29 | /** 30 | * 文字的宽度 31 | */ 32 | private var mViewWidth = 0 33 | /** 34 | * 段落间距 35 | */ 36 | private val paragraphSpacing = dipToPx(getContext(), 15f) 37 | /** 38 | * 行间距 39 | */ 40 | private val lineSpacing = dipToPx(getContext(), 2f) 41 | /** 42 | * 当前所有行数的集合 43 | */ 44 | private var mParagraphLineList: ArrayList>>? = 45 | null 46 | /** 47 | * 当前所有的行数 48 | */ 49 | private var mLineCount = 0 50 | /** 51 | * 每一段单词的内容集合 52 | */ 53 | private var mParagraphWordList: ArrayList>? = 54 | null 55 | /** 56 | * 英语单词元音字母 57 | */ 58 | private val vowel = arrayOf("a", "e", "i", "o", "u") 59 | /** 60 | * 英语单词元音字母集合 61 | */ 62 | private val vowels = 63 | Arrays.asList(*vowel) 64 | /** 65 | * 当前测量的间距 66 | */ 67 | private var mMeasuredWidth = 0 68 | /** 69 | * 左padding 70 | */ 71 | private var mPaddingStart = 0 72 | /** 73 | * 右padding 74 | */ 75 | private var mPaddingEnd = 0 76 | /** 77 | * 顶padding 78 | */ 79 | private var mPaddingTop = 0 80 | /** 81 | * 底padding 82 | */ 83 | private var mPaddingBottom = 0 84 | /** 85 | * 布局的方向 86 | */ 87 | private var textGravity = 0 88 | 89 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { 90 | super.onMeasure(widthMeasureSpec, heightMeasureSpec) 91 | mParagraphLineList = null 92 | mParagraphWordList = null 93 | mLineY = 0f 94 | mMeasuredWidth = getMeasuredWidth() 95 | mPaddingStart = getPaddingStart() 96 | mPaddingEnd = getPaddingEnd() 97 | mPaddingTop = getPaddingTop() 98 | mPaddingBottom = getPaddingBottom() 99 | mViewWidth = mMeasuredWidth - mPaddingStart - mPaddingEnd 100 | paragraphList 101 | for (frontList in mParagraphWordList!!) { 102 | mParagraphLineList!!.add(getLineList(frontList)) 103 | } 104 | setMeasuredDimension( 105 | mMeasuredWidth, 106 | (mParagraphLineList!!.size - 1) * paragraphSpacing + mLineCount * (lineHeight + lineSpacing) + mPaddingTop + mPaddingBottom 107 | ) 108 | } 109 | 110 | override fun onDraw(canvas: Canvas) { 111 | val paint = paint 112 | paint.color = currentTextColor 113 | paint.drawableState = drawableState 114 | mLineY = 0f 115 | val textSize = textSize 116 | mLineY += textSize + mPaddingTop 117 | val layout = layout ?: return 118 | textGravity = getTextGravity() 119 | adjust(canvas, paint) 120 | } 121 | 122 | /** 123 | * @param frontList 124 | * @return 计算每一段绘制的内容 125 | */ 126 | @Synchronized 127 | private fun getLineList(frontList: List): List> { 128 | Log.i(TAG, "getLineList ") 129 | val sb = StringBuilder() 130 | val lineLists: MutableList> = 131 | ArrayList() 132 | val lineList: MutableList = 133 | ArrayList() 134 | var width = 0f 135 | var temp = "" 136 | var front = "" 137 | for (i in frontList.indices) { 138 | front = frontList[i] 139 | if (!TextUtils.isEmpty(temp)) { 140 | sb.append(temp) 141 | lineList.add(temp) 142 | if (!isCN(temp)) { 143 | sb.append(BLANK) 144 | } 145 | temp = "" 146 | } 147 | if (isCN(front)) { 148 | sb.append(front) 149 | } else { 150 | if (i + 1 < frontList.size) { 151 | val nextFront = frontList[i + 1] 152 | if (isCN(nextFront)) { 153 | sb.append(front) 154 | } else { 155 | sb.append(front).append(BLANK) 156 | } 157 | } else { 158 | sb.append(front) 159 | } 160 | } 161 | lineList.add(front) 162 | width = StaticLayout.getDesiredWidth(sb.toString(), paint) 163 | if (width > mViewWidth) { // 先判断最后一个单词是否是英文的,是的话则切割,否则的话就移除最后一个 164 | val lastIndex = lineList.size - 1 165 | val lastWord = lineList[lastIndex] 166 | var lastTemp = "" 167 | lineList.removeAt(lastIndex) 168 | if (isCN(lastWord)) { 169 | addLines(lineLists, lineList) 170 | lastTemp = lastWord 171 | } else { // 否则的话则截取字符串 172 | val substring = sb.substring(0, sb.length - lastWord.length - 1) 173 | sb.delete(0, sb.toString().length) 174 | sb.append(substring).append(BLANK) 175 | var tempLastWord = "" 176 | val length = lastWord.length 177 | if (length <= 3) { 178 | addLines(lineLists, lineList) 179 | lastTemp = lastWord 180 | } else { 181 | var cutoffIndex = 0 182 | for (j in 0 until length) { 183 | tempLastWord = lastWord[j].toString() 184 | sb.append(tempLastWord) 185 | if (tempLastWord in vowels) { // 根据元音字母来进行截断 186 | if (j + 1 < length) { 187 | val nextTempLastWord = 188 | lastWord[j + 1].toString() 189 | sb.append(nextTempLastWord) 190 | width = StaticLayout.getDesiredWidth(sb.toString(), paint) 191 | cutoffIndex = j 192 | if (width > mViewWidth) { 193 | lastTemp = 194 | if (j > 2 && j <= length - 2) { // 单词截断后,前面的字符小于2个时,则不进行截断 195 | val lastFinalWord = 196 | lastWord.substring(0, cutoffIndex + 2) + "-" 197 | lineList.add(lastFinalWord) 198 | addLines(lineLists, lineList) 199 | lastWord.substring(cutoffIndex + 2, length) 200 | } else { 201 | addLines(lineLists, lineList) 202 | lastWord 203 | } 204 | break 205 | } 206 | } else { 207 | addLines(lineLists, lineList) 208 | lastTemp = lastWord 209 | break 210 | } 211 | } 212 | width = StaticLayout.getDesiredWidth(sb.toString(), paint) 213 | // 找不到元音,则走默认的逻辑 214 | if (width > mViewWidth) { 215 | lastTemp = 216 | if (j > 2 && j <= length - 2) { // 单词截断后,前面的字符小于2个时,则不进行截断 217 | val lastFinalWord = 218 | lastWord.substring(0, j) + "-" 219 | lineList.add(lastFinalWord) 220 | addLines(lineLists, lineList) 221 | lastWord.substring(j, length) 222 | } else { 223 | addLines(lineLists, lineList) 224 | lastWord 225 | } 226 | break 227 | } 228 | } 229 | } 230 | } 231 | sb.delete(0, sb.toString().length) 232 | temp = lastTemp 233 | } 234 | if (lineList.size > 0 && i == frontList.size - 1) { 235 | addLines(lineLists, lineList) 236 | } 237 | } 238 | if (!TextUtils.isEmpty(temp)) { 239 | lineList.add(temp) 240 | addLines(lineLists, lineList) 241 | } 242 | mLineCount += lineLists.size 243 | return lineLists 244 | } 245 | 246 | /** 247 | * 添加一行到单词内容 248 | * 249 | * @param lineLists 总单词集合 250 | * @param lineList 当前要添加的集合 251 | */ 252 | private fun addLines( 253 | lineLists: MutableList>?, 254 | lineList: MutableList? 255 | ) { 256 | if (lineLists == null || lineList == null) { 257 | return 258 | } 259 | val tempLines: List = 260 | ArrayList(lineList) 261 | lineLists.add(tempLines) 262 | lineList.clear() 263 | } 264 | 265 | /** 266 | * 获取段落 267 | */ 268 | private val paragraphList: Unit 269 | private get() { 270 | val text = 271 | text.toString().replace(" ".toRegex(), "").replace(" ".toRegex(), "") 272 | .replace("\\r".toRegex(), "").trim { it <= ' ' } 273 | mLineCount = 0 274 | val items = text.split("\\n").toTypedArray() 275 | mParagraphLineList = 276 | ArrayList() 277 | mParagraphWordList = ArrayList() 278 | for (item in items) { 279 | if (item.length != 0) { 280 | mParagraphWordList!!.add(getWordList(item)) 281 | } 282 | } 283 | } 284 | 285 | /** 286 | * 截取每一段内容的每一个单词 287 | * 288 | * @param text 289 | * @return 290 | */ 291 | @Synchronized 292 | private fun getWordList(text: String): List { 293 | if (TextUtils.isEmpty(text)) { 294 | return ArrayList() 295 | } 296 | Log.i(TAG, "getWordList ") 297 | val frontList: MutableList = 298 | ArrayList() 299 | val str = StringBuilder() 300 | for (i in 0 until text.length) { 301 | val charAt = text[i].toString() 302 | if (charAt != BLANK) { 303 | if (checkIsSymbol(charAt)) { 304 | val isEmptyStr = str.length == 0 305 | str.append(charAt) 306 | if (!isEmptyStr) { // 中英文都需要将字符串添加到这里; 307 | frontList.add(str.toString()) 308 | str.delete(0, str.length) 309 | } 310 | } else { 311 | if (isCN(str.toString())) { 312 | frontList.add(str.toString()) 313 | str.delete(0, str.length) 314 | } 315 | str.append(charAt) 316 | } 317 | } else { 318 | if (!TextUtils.isEmpty(str.toString())) { 319 | frontList.add( 320 | str.toString().replace( 321 | BLANK.toRegex(), 322 | "" 323 | ) 324 | ) 325 | str.delete(0, str.length) 326 | } 327 | } 328 | } 329 | if (str.length != 0) { 330 | frontList.add(str.toString()) 331 | str.delete(0, str.length) 332 | } 333 | return frontList 334 | } 335 | 336 | /** 337 | * 中英文排版效果 338 | * 339 | * @param canvas 340 | */ 341 | @Synchronized 342 | private fun adjust(canvas: Canvas, paint: TextPaint) { 343 | val size = mParagraphWordList!!.size 344 | for (j in 0 until size) { // 遍历每一段 345 | val lineList = 346 | mParagraphLineList!![j] 347 | for (i in lineList.indices) { // 遍历每一段的每一行 348 | val lineWords = lineList[i] 349 | if (i == lineList.size - 1) { 350 | drawScaledEndText(canvas, lineWords, paint) 351 | } else { 352 | drawScaledText(canvas, lineWords, paint) 353 | } 354 | mLineY += (lineHeight + lineSpacing).toFloat() 355 | } 356 | mLineY += paragraphSpacing.toFloat() 357 | } 358 | } 359 | 360 | /** 361 | * 绘制最后一行文字 362 | * 363 | * @param canvas 364 | * @param lineWords 365 | * @param paint 366 | */ 367 | private fun drawScaledEndText( 368 | canvas: Canvas?, 369 | lineWords: List?, 370 | paint: TextPaint? 371 | ) { 372 | if (canvas == null || lineWords == null || paint == null) { 373 | return 374 | } 375 | val sb = StringBuilder() 376 | for (aSplit in lineWords) { 377 | if (isCN(aSplit)) { 378 | sb.append(aSplit) 379 | } else { 380 | sb.append(aSplit).append(BLANK) 381 | } 382 | } 383 | /** 384 | * 最后一行适配布局方向 385 | * android:gravity="" 386 | * android:textAlignment="" 387 | * 默认不设置则为左边 388 | * 如果同时设置gravity和textAlignment属性,则以textAlignment的属性为准 389 | * 也就是说textAlignment的属性优先级大于gravity的属性 390 | * 391 | */ 392 | if (GRAVITY_START == textGravity) { 393 | canvas.drawText(sb.toString(), mPaddingStart.toFloat(), mLineY, paint) 394 | } else if (GRAVITY_END == textGravity) { 395 | val width = StaticLayout.getDesiredWidth(sb.toString(), getPaint()) 396 | canvas.drawText(sb.toString(), mMeasuredWidth - width - mPaddingStart, mLineY, paint) 397 | } else { 398 | val width = StaticLayout.getDesiredWidth(sb.toString(), getPaint()) 399 | canvas.drawText(sb.toString(), (mViewWidth - width) / 2, mLineY, paint) 400 | } 401 | } 402 | 403 | /** 404 | * 获取布局的方向 405 | */ 406 | private fun getTextGravity(): Int { 407 | val layoutDirection = layoutDirection 408 | val absoluteGravity = 409 | Gravity.getAbsoluteGravity(gravity, layoutDirection) 410 | val lastGravity = absoluteGravity and Gravity.HORIZONTAL_GRAVITY_MASK 411 | val textAlignment = textAlignment 412 | return if (View.TEXT_ALIGNMENT_TEXT_START == textAlignment || View.TEXT_ALIGNMENT_VIEW_START == textAlignment || Gravity.LEFT == lastGravity 413 | ) { 414 | GRAVITY_START 415 | } else if (View.TEXT_ALIGNMENT_TEXT_END == textAlignment || View.TEXT_ALIGNMENT_VIEW_END == textAlignment || Gravity.RIGHT == lastGravity 416 | ) { 417 | GRAVITY_END 418 | } else { 419 | GRAVITY_CENTER 420 | } 421 | } 422 | 423 | /** 424 | * 绘制左右对齐效果 425 | * 426 | * @param canvas 427 | * @param line 428 | * @param paint 429 | */ 430 | private fun drawScaledText( 431 | canvas: Canvas?, 432 | line: List?, 433 | paint: TextPaint? 434 | ) { 435 | if (canvas == null || line == null || paint == null) { 436 | return 437 | } 438 | val sb = StringBuilder() 439 | for (aSplit in line) { 440 | sb.append(aSplit) 441 | } 442 | val lineWidth = StaticLayout.getDesiredWidth(sb, getPaint()) 443 | var cw = 0f 444 | cw = if (GRAVITY_START == textGravity) { 445 | mPaddingStart.toFloat() 446 | } else if (GRAVITY_END == textGravity) { 447 | mPaddingEnd.toFloat() 448 | } else { 449 | mPaddingStart.toFloat() 450 | } 451 | val d = (mViewWidth - lineWidth) / (line.size - 1) 452 | for (aSplit in line) { 453 | canvas.drawText(aSplit, cw, mLineY, getPaint()) 454 | cw += StaticLayout.getDesiredWidth(aSplit + "", paint) + d 455 | } 456 | } 457 | 458 | /** 459 | * 功能:判断字符串是否有中文 460 | * 461 | * @param str 462 | * @return 463 | */ 464 | fun isCN(str: String): Boolean { 465 | try { 466 | val bytes = str.toByteArray(charset("UTF-8")) 467 | return if (bytes.size == str.length) { 468 | false 469 | } else { 470 | true 471 | } 472 | } catch (e: UnsupportedEncodingException) { // TODO Auto-generated catch block 473 | e.printStackTrace() 474 | } 475 | return false 476 | } 477 | 478 | /** 479 | * 判断是否包含标点符号等内容 480 | * 481 | * @param s 482 | * @return 483 | */ 484 | fun checkIsSymbol(s: String): Boolean { 485 | var b = false 486 | var tmp = s 487 | tmp = tmp.replace("\\p{P}".toRegex(), "") 488 | if (s.length != tmp.length) { 489 | b = true 490 | } 491 | return b 492 | } 493 | 494 | companion object { 495 | private val TAG = XCJustifyTextView::class.java.simpleName 496 | /** 497 | * 起始位置 498 | */ 499 | private const val GRAVITY_START = 1001 500 | /** 501 | * 结尾位置 502 | */ 503 | private const val GRAVITY_END = 1002 504 | /** 505 | * 中间位置 506 | */ 507 | private const val GRAVITY_CENTER = 1003 508 | /** 509 | * 空格字符 510 | */ 511 | private const val BLANK = " " 512 | 513 | fun dipToPx(var0: Context, var1: Float): Int { 514 | val var2 = var0.resources.displayMetrics.density 515 | return (var1 * var2 + 0.5f).toInt() 516 | } 517 | } 518 | } 519 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 47 | 60 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | --------------------------------------------------------------------------------