Android-активность, содержащая медленно открывающееся окно просмотра - PullRequest
0 голосов
/ 14 ноября 2018

Я пытаюсь перейти от одного занятия к другому. Второе действие имеет просмотрщик, имеющий три фрагмента. Два фрагмента имеют много просмотров, а один - меньше. Я попытался сохранить только один фрагмент в окне просмотра, которое имеет много просмотров. Потребовалось некоторое время для загрузки. Я попробовал другой с большим количеством просмотров. Это также заняло время, чтобы загрузить. Но когда я сохранил фрагмент с меньшим количеством просмотров, это заняло меньше времени. Если я загружаю все сразу, это снова занимает много времени для загрузки. Сначала у меня было много иерархий представлений для обоих фрагментов, но в итоге я удалил их все, используя макет таблицы. Активность замедляется. фрагмент 1:

    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TableRow style="@style/TableRowStyle">

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                </TableRow>

                <TableRow style="@style/TableRowStyle">

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                </TableRow>

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white">

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/white" />

                </TableRow>

                <TableRow style="@style/TableRowStyle">

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1.5"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                </TableRow>


                <TableRow style="@style/TableRowStyle">

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1.5" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                </TableRow>

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white">

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/white" />

                </TableRow>

                <TableRow
                    android:id="@+id/ll_nfo1"
                    style="@style/TableRowStyle"
                    android:visibility="visible">

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                </TableRow>

                <TableRow android:id="@+id/ll_nfo2"
                    style="@style/TableRowStyle"
                    android:visibility="visible">

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                </TableRow>

                <TableRow style="@style/BidOfferTableRowStyle">

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                </TableRow>

                <TableRow style="@style/BidOfferTableRowStyle">

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                </TableRow>

                <TableRow style="@style/BidOfferTableRowStyle">

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                </TableRow>

                <TableRow style="@style/BidOfferTableRowStyle">

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                </TableRow>

                <TableRow style="@style/BidOfferTableRowStyle">

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <com.intmilli.imobile.Views.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                </TableRow>

            </TableLayout>


        </LinearLayout>

    </ScrollView>

    <LinearLayout
        android:id="@+id/ll_bottom"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dimen_40">

        <com.intmilli.imobile.Views.CustomTextView
            android:id="@+id/tv_h_first"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"/>

        <View
            android:id="@+id/view_line3_left"
            android:layout_height="match_parent"
            android:layout_toRightOf="@id/tv_h_first"
            android:background="@color/mainbg_lightblue" />

        <com.intmilli.imobile.Views.CustomTextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1" />
    </LinearLayout>

</RelativeLayout>

фрагмент 3:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                />

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="4dp"
            android:paddingBottom="4dp">

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <Spinner
                android:id="@+id/day_spinner"
                android:layout_width="0dp"
                android:layout_height="34dp" />

            <Spinner
                android:id="@+id/limit_spinner"
                android:layout_width="0dp"
                android:layout_height="34dp" />

            <Spinner
                android:id="@+id/buy_spinner"
                android:layout_width="0dp"
                android:layout_height="34dp" />

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp">

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

            <ImageButton
                android:id="@+id/sub_qty"
                android:layout_width="0dp"
                android:layout_height="36dp"
                android:layout_weight="0.3" />

            <EditText
                android:id="@+id/et_qty"
                android:layout_width="0dp"
                android:layout_height="36dp"/>

            <ImageButton
                android:id="@+id/add_qty"
                android:layout_width="0dp"
                android:layout_height="36dp"
                android:layout_weight="0.3"/>

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp">

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <ImageButton
                android:id="@+id/sub_price"
                android:layout_width="0dp"
                android:layout_height="36dp"
                android:layout_weight="0.3" />

            <EditText
                android:id="@+id/et_pricevalue"
                android:layout_width="0dp"
                android:layout_height="36dp" />

            <ImageButton
                android:id="@+id/add_price"
                android:layout_width="0dp"
                android:layout_height="36dp"
                android:layout_weight="0.3" />

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp">

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

            <ImageButton
                android:id="@+id/sub_dis_qty"
                android:layout_width="0dp"
                android:layout_height="36dp"
                android:layout_weight="0.3"/>

            <EditText
                android:id="@+id/et_dis_qty"
                android:layout_width="0dp"
                android:layout_height="36dp" />

            <ImageButton
                android:id="@+id/add_dis_qty"
                android:layout_width="0dp"
                android:layout_height="36dp"
                android:layout_weight="0.3"/>


        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp">

            <com.intmilli.imobile.Views.CustomTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

            <ImageButton
                android:id="@+id/sub_tri_price"
                android:layout_width="0dp"
                android:layout_height="36dp"
                android:layout_weight="0.3"/>

            <EditText
                android:id="@+id/et_triggerPrice"
                android:layout_width="0dp"
                android:layout_height="36dp" />

            <ImageButton
                android:id="@+id/add_tri_price"
                android:layout_width="0dp"
                android:layout_height="36dp"
                android:layout_weight="0.3" />

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="6dp">

            <CheckBox
                android:id="@+id/ch_stopLoss"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <CheckBox
                android:id="@+id/ch_IOC"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center">

            <com.intmilli.imobile.Views.CustomTextView
                android:id="@+id/tv_placeOrderBtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </TableRow>

    </TableLayout>

</ScrollView>

Как я уже говорил, фрагменты 1 и 3 занимают много времени. Может кто-нибудь помочь решить эту проблему спасибо!

1 Ответ

0 голосов
/ 14 ноября 2018
  • Вес не годится для большого использования. Я видел, что вы использовали слишком много android:layout_weight в вашем макете. Это вызывает медленную загрузку макета. Потому что это необходимо настроить представления в соответствии с экраном устройства.

    Так что не используйте слишком много весов и используйте RelativeLayout или ConstraintLayout.

  • Не пишите никакой логики, выборки данных, управления представлениями внутри onCreate() или onCreateView().
  • Делать все findViewById() в onViewCreated() фрагментов. Также прочитайте Фрагмент жизненного цикла для лучшего понимания.
  • Если вы вызываете API, тогда звоните с с некоторой задержкой в onViewCreated(). Это позволит сначала просматривать созданные, а затем устанавливать данные, полученные из API.
  • Обратите внимание, что вы не выполняете никаких длительных операций или логики в пользовательском интерфейсе или главном потоке. Это должно быть сделано в рабочем потоке , например AsyncTask или новом потоке.
...