├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-hdpi │ │ │ │ └── test.png │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── styles.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── strings.xml │ │ │ ├── layout │ │ │ │ ├── normal_list_item.xml │ │ │ │ ├── static_list_item.xml │ │ │ │ ├── activity_normal_long_string_ui.xml │ │ │ │ ├── activity_static_long_string_ui.xml │ │ │ │ ├── activity_static_layout_ui.xml │ │ │ │ ├── activity_normal_layout_ui.xml │ │ │ │ └── activity_main.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── menu │ │ │ │ ├── menu_main.xml │ │ │ │ ├── menu_normal_layout_ui.xml │ │ │ │ ├── menu_static_layout_ui.xml │ │ │ │ ├── menu_normal_long_string_ui.xml │ │ │ │ └── menu_static_long_string_ui.xml │ │ ├── gen │ │ │ └── com │ │ │ │ └── ragnarok │ │ │ │ └── staticlayouttest │ │ │ │ └── app │ │ │ │ ├── R.java │ │ │ │ ├── Manifest.java │ │ │ │ └── BuildConfig.java │ │ ├── main.iml │ │ ├── java │ │ │ └── com │ │ │ │ └── ragnarok │ │ │ │ └── staticlayoutview │ │ │ │ ├── util │ │ │ │ ├── Util.java │ │ │ │ ├── GhostThread.java │ │ │ │ ├── FpsCalculator.java │ │ │ │ └── TestSpan.java │ │ │ │ └── ui │ │ │ │ ├── NormalLongStringUI.java │ │ │ │ ├── StaticLongStringUI.java │ │ │ │ ├── StaticLayoutView.java │ │ │ │ ├── StaticLayoutManager.java │ │ │ │ ├── AutoScrollHandler.java │ │ │ │ ├── NormalLayoutUI.java │ │ │ │ ├── StaticLayoutUI.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ └── androidTest │ │ ├── java │ │ └── com │ │ │ └── ragnarok │ │ │ └── staticlayouttest │ │ │ └── app │ │ │ └── ApplicationTest.java │ │ └── androidTest1.iml ├── proguard-rules.pro ├── build.gradle └── app.iml ├── settings.gradle ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── gradle.properties ├── StaticLayoutView.iml ├── LICENSE ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | local.properties 3 | .idea/ 4 | .idea/workspace.xml 5 | .idea/libraries 6 | .DS_Store 7 | build/ 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragnraok/StaticLayoutView/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragnraok/StaticLayoutView/HEAD/app/src/main/res/drawable-hdpi/test.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragnraok/StaticLayoutView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragnraok/StaticLayoutView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragnraok/StaticLayoutView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragnraok/StaticLayoutView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/gen/com/ragnarok/staticlayouttest/app/R.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package com.ragnarok.staticlayouttest.app; 4 | 5 | /* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */ 6 | public final class R { 7 | } -------------------------------------------------------------------------------- /app/src/main/gen/com/ragnarok/staticlayouttest/app/Manifest.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package com.ragnarok.staticlayouttest.app; 4 | 5 | /* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */ 6 | public final class Manifest { 7 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 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-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/normal_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/static_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/gen/com/ragnarok/staticlayouttest/app/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package com.ragnarok.staticlayouttest.app; 4 | 5 | /* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */ 6 | public final class BuildConfig { 7 | public final static boolean DEBUG = Boolean.parseBoolean(null); 8 | } -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/ragnarok/staticlayouttest/app/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.ragnarok.staticlayouttest.app; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_normal_layout_ui.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_static_layout_ui.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/androidTest/androidTest1.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_normal_long_string_ui.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_static_long_string_ui.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | StaticLayoutTest 3 | 4 | Hello world! 5 | Settings 6 | StaticLayoutUI 7 | NormalLayoutUI 8 | StaticLongStringUI 9 | NormalLongStringUI 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # StaticLayoutView 2 | a pre-render TextView demo 3 | 4 | This demo use StaticLayout to render text in a custom TextView and create the StaticLayout in another thread before enter the UI, and these StaticLayout draw in a dummy canvas which warm up the TextLayoutCache in the system. And these optimization improve the performance of showing complicated text(which may include many spans, emoji) in a ListView 5 | 6 | for the detail of this project, please read this post(in chinese): [http://ragnraok.github.io/textview-pre-render-research.html](http://ragnraok.github.io/textview-pre-render-research.html) 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_normal_long_string_ui.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_static_long_string_ui.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/ragnarok/adt-bundle-mac-x86_64-20131030/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /StaticLayoutView.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:1.1.1' 7 | } 8 | } 9 | apply plugin: 'com.android.application' 10 | 11 | repositories { 12 | jcenter() 13 | } 14 | 15 | android { 16 | compileSdkVersion 22 17 | buildToolsVersion "22.0.1" 18 | 19 | defaultConfig { 20 | applicationId "com.ragnarok.staticlayouttest.app" 21 | minSdkVersion 15 22 | targetSdkVersion 22 23 | versionCode 1 24 | versionName "1.0" 25 | } 26 | buildTypes { 27 | release { 28 | minifyEnabled false 29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 30 | } 31 | } 32 | } 33 | 34 | dependencies { 35 | compile fileTree(dir: 'libs', include: ['*.jar']) 36 | compile 'com.android.support:appcompat-v7:22.2.0' 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/main.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/ragnarok/staticlayoutview/util/Util.java: -------------------------------------------------------------------------------- 1 | package com.ragnarok.staticlayoutview.util; 2 | 3 | import android.content.Context; 4 | import android.graphics.Point; 5 | import android.view.WindowManager; 6 | 7 | /** 8 | * Created by ragnarok on 15/7/21. 9 | */ 10 | public class Util { 11 | 12 | public static final int TEST_LIST_ITEM_COUNT = 300; 13 | 14 | public static final int TEXT_SIZE_DP = 25; 15 | 16 | public static final int AUTO_SCROLL_INTERVAL = 1; 17 | 18 | public static final int AUTO_SCROLL_STEP = 10; 19 | 20 | public static float fromDPtoPix(Context context, int dp) { 21 | return context.getResources().getDisplayMetrics().density * dp; 22 | } 23 | 24 | public static int getScreenWidth(Context context) { 25 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 26 | 27 | Point size = new Point(); 28 | windowManager.getDefaultDisplay().getSize(size); 29 | 30 | return size.x; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 RagnarokStack 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_static_layout_ui.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 13 | 14 |