Java Android性能优化问题(具有合理的TextView和CodeView的布局)

Java Android性能优化问题(具有合理的TextView和CodeView的布局),java,android,xml,android-linearlayout,Java,Android,Xml,Android Linearlayout,我的问题是,当我打开一个充满justizedTextView和CodeView的活动时,我的应用程序相当慢 implementation 'com.github.softwee:codeview-android:1.1.2' implementation 'com.uncopt:android.justified:1.0' 我使用这些库是为了获得合理的文本,并能够使用语法高亮 问题A:这些第三方库是否可能使我的应用程序运行缓慢?有时会跳过100-150帧 问题B:独自做这些事情是一个好方法吗?

我的问题是,当我打开一个充满justizedTextView和CodeView的活动时,我的应用程序相当慢

implementation 'com.github.softwee:codeview-android:1.1.2'
implementation 'com.uncopt:android.justified:1.0'
我使用这些库是为了获得合理的文本,并能够使用语法高亮

问题A:这些第三方库是否可能使我的应用程序运行缓慢?有时会跳过100-150帧

问题B:独自做这些事情是一个好方法吗?那么,我自己实现文本对齐等

问题C:在数据库(SQLite)中存储字符串是否比使用strings.xml更好

这是活动的确切源代码示例:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout 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"
    android:background="@android:color/white"
    android:orientation="vertical"
    android:padding="20dp"
    tools:context=".SortingMainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#858a9f"
        android:paddingTop="20dp"
        android:paddingBottom="20dp"
        android:textSize="20dp"
        android:text="What is Bogo Sort?"
        android:textStyle="bold"
        app:fontFamily="@font/roboto_slab" />

    <com.uncopt.android.widget.text.justify.JustifiedTextView
        android:id="@+id/bogoSortFirstParagraph"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#858a9f"
        android:textSize="18dp"
        app:fontFamily="@font/roboto_slab"
        android:paddingBottom="10dp"/>

    <com.uncopt.android.widget.text.justify.JustifiedTextView
        android:id="@+id/bogoDeterministic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:textColor="#858a9f"
        android:textSize="18dp"
        app:fontFamily="@font/roboto_slab" />

    <com.uncopt.android.widget.text.justify.JustifiedTextView
        android:id="@+id/bogoRandom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:textColor="#858a9f"
        android:textSize="18dp"
        app:fontFamily="@font/roboto_slab" />

    <com.uncopt.android.widget.text.justify.JustifiedTextView
        android:id="@+id/bogoEssence"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:textColor="#858a9f"
        android:textSize="18dp"
        app:fontFamily="@font/roboto_slab" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#858a9f"
        android:paddingTop="10dp"
        android:paddingBottom="20dp"
        android:textSize="20dp"
        android:text="Implementation"
        android:textStyle="bold"
        app:fontFamily="@font/roboto_slab" />

    <com.uncopt.android.widget.text.justify.JustifiedTextView
        android:id="@+id/bogoFisherYates"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:textColor="#858a9f"
        android:textSize="18dp"
        app:fontFamily="@font/roboto_slab" />

    <io.github.kbiakov.codeview.CodeView
        android:id="@+id/shuffleCodeView"
        android:paddingBottom="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <com.uncopt.android.widget.text.justify.JustifiedTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:textColor="#858a9f"
        android:textSize="18dp"
        android:text="@string/bogoTheory1"
        app:fontFamily="@font/roboto_slab" />

    <io.github.kbiakov.codeview.CodeView
        android:id="@+id/swapCodeView"
        android:paddingBottom="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <com.uncopt.android.widget.text.justify.JustifiedTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:textColor="#858a9f"
        android:textSize="18dp"
        android:text="@string/bogoTheory2"
        app:fontFamily="@font/roboto_slab" />

    <io.github.kbiakov.codeview.CodeView
        android:id="@+id/isSortedCodeView"
        android:layout_width="match_parent"
        android:paddingBottom="10dp"
        android:layout_height="wrap_content"/>

    <com.uncopt.android.widget.text.justify.JustifiedTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:textColor="#858a9f"
        android:textSize="18dp"
        android:text="@string/bogoTheory3"
        app:fontFamily="@font/roboto_slab" />

    <io.github.kbiakov.codeview.CodeView
        android:id="@+id/sortCodeView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>


如果不进行分析,很难确定,但好的第一步可能是使用渲染器仅渲染屏幕上的部分,而不必使用当前的
LinearLayout
/
ScrollView
设置来布局整个内容


要确定这一点,或者作为之后的下一步,您应该尝试从Android Studio拍摄一张照片,看看是什么原因导致了掉帧期间的大部分工作。

谢谢您的回答!哇,那个追踪器太棒了!