У меня есть приложение, которое показывает фрагмент Dashboard при запуске.Я только разработал пользовательский интерфейс (XML) и заметил, что при запуске мое приложение открывается примерно за 1,5 секунды, в то время как другие приложения на моем телефоне занимают менее 0,5 секунды.Я думаю, что графический рендеринг занимает слишком много памяти, или, может быть, я разработал его неправильно.
Мой код пользовательского интерфейса выглядит следующим образом:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--
Main Content
-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical">
<!--
The Upper layer
-->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/upper_layer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="100dp"
android:background="@color/colorAccent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" app:srcCompat="@drawable/img_user_colored_1"
android:id="@+id/imageView" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@drawable/img_user_colored_1"
app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintVertical_chainStyle="packed" android:layout_marginTop="8dp"/>
<TextView
android:text="Welcome, Mervin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView2" app:layout_constraintStart_toStartOf="@+id/imageView"
app:layout_constraintEnd_toEndOf="@+id/imageView" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/imageView"
tools:text="Title" app:layout_constraintBottom_toTopOf="@+id/textView3"
android:textColor="@color/colorTextSecondary"
style="@style/typography_h6"/>
<TextView
android:text="@string/TextView_fromDashboardFragment_Title_Main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView3"
tools:text="@string/TextView_fromDashboardFragment_Title_Main"
app:layout_constraintStart_toStartOf="@+id/imageView"
app:layout_constraintEnd_toEndOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/textView2"
android:textColor="@color/colorTextSecondary"
style="@style/typography_caption"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<!--
The lower content.
-->
<LinearLayout
android:id="@+id/lower_layer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="100dp"
android:layout_marginBottom="?attr/actionBarSize"
android:paddingBottom="16dp">
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
layout="@layout/include_forfragmentdashboard_section_goal"/>
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
layout="@layout/include_forfragmentdashboard_section_todo"/>
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
layout="@layout/include_forfragmentdashboard_section_tobuy"/>
</LinearLayout>
</LinearLayout>
<!--
The anchored CardView on the middle of the screen
-->
<com.google.android.material.card.MaterialCardView
android:id="@+id/active_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:cardBackgroundColor="@color/cardView_background_default"
app:cardElevation="@dimen/Elevation_CardView_Simple"
app:layout_anchor="@+id/upper_layer"
app:layout_anchorGravity="center_horizontal|bottom">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/Padding_CardView_Simple"
android:paddingBottom="@dimen/Padding_CardView_Simple"
android:orientation="vertical"
android:baselineAligned="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Active"
style="@style/typography_overline"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:baselineAligned="false">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="14"
android:textColor="@color/colorAccent"
style="@style/typography_h2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="@string/App_Lifestyle_Task_Goal_Title"
style="@style/typography_caption"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:baselineAligned="false">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="2"
android:textColor="@color/colorAccent"
style="@style/typography_h2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="@string/App_Lifestyle_Task_ToDo_Title"
style="@style/typography_caption"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:baselineAligned="false">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="24"
android:textColor="@color/colorAccent"
style="@style/typography_h2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="@string/App_Lifestyle_Task_ToBuy_Title"
style="@style/typography_caption"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
include_forfragmentdashboard_section_tobuy.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="@string/App_Lifestyle_Task_ToBuy_Title"
style="@style/Centered_Subtitle_Overline_Default"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:orientation="horizontal"
android:weightSum="2"
android:baselineAligned="false">
<com.google.android.material.card.MaterialCardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:cardBackgroundColor="@color/cardView_background_default"
app:cardElevation="@dimen/Elevation_CardView_Simple">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginBottom="@dimen/Margin_CardView_Simple"
android:orientation="vertical"
android:baselineAligned="false">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="4"
android:textColor="@color/colorAccent"
style="@style/typography_h2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="All Time"
style="@style/typography_caption"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:cardBackgroundColor="@color/cardView_background_default"
app:cardElevation="@dimen/Elevation_CardView_Simple">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginBottom="@dimen/Margin_CardView_Simple"
android:orientation="vertical"
android:baselineAligned="false">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="56"
android:textColor="@color/colorAccent"
style="@style/typography_h2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="Completed"
style="@style/typography_caption"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:text="Priorities"
android:textColor="@color/colorTextAlternateLight"
style="@style/typography_caption"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="horizontal"
android:baselineAligned="false"
android:weightSum="2">
<ProgressBar
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:max="@integer/ProgressBar_Default_MaxProgress"
android:progress="56"
android:progressTint="@color/item_priority_1"
android:scaleY="@integer/ProgressBar_Default_ScaleY"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>
<ProgressBar
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:max="@integer/ProgressBar_Default_MaxProgress"
android:progress="56"
android:progressTint="@color/item_priority_2"
android:scaleY="@integer/ProgressBar_Default_ScaleY"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="horizontal"
android:baselineAligned="false"
android:weightSum="2">
<ProgressBar
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:max="@integer/ProgressBar_Default_MaxProgress"
android:progress="56"
android:progressTint="@color/item_priority_3"
android:scaleY="@integer/ProgressBar_Default_ScaleY"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>
<ProgressBar
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:max="@integer/ProgressBar_Default_MaxProgress"
android:progress="56"
android:progressTint="@color/item_priority_4"
android:scaleY="@integer/ProgressBar_Default_ScaleY"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>
</LinearLayout>
</LinearLayout>
Вывод:
![UI-1](https://i.stack.imgur.com/dAGhD.png)
![UI-2](https://i.stack.imgur.com/kkbyf.png)
Может кто-нибудь помочьмне в улучшении пользовательского интерфейса с помощью некоторых кодов или лучших практик пользовательского интерфейса, которым я могу следовать, чтобы полностью оптимизировать свой пользовательский интерфейс?Есть ли какие-то коды, которые вы можете ввести в xml или код, чтобы уменьшить перерасход?Пожалуйста, помогите мне.