我爲我的應用程序設計了一個設計,但運行速度非常慢。我試圖達到的結果是這樣的:Android XML設計(佈局)讓我的應用程序變得如此緩慢
到目前爲止,我已經能夠達到這個結果與該XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.asteam.unify.Mbajtje">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_marginRight="@dimen/general_margin"
android:layout_marginLeft="@dimen/general_margin">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lendaText"
android:layout_marginTop="@dimen/general_margin"
android:text="Lënda:"/>
<Spinner
android:id="@+id/lendaMbajtje"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lendaText"
android:textSize="@dimen/font_size"
android:background="@drawable/border_bottom"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/subjektiText"
android:layout_marginTop="@dimen/general_margin"
android:layout_below="@id/lendaMbajtje"
android:text="Subjekti:"/>
<Spinner
android:id="@+id/subjektiMbajtje"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/subjektiText"
android:textSize="@dimen/font_size"
android:background="@drawable/border_bottom"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/subjektiMbajtje"
android:id="@+id/detajetMbajtjesText"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="@dimen/general_margin"
android:layout_weight="3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:text="Data e mbajtjes:"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:id="@+id/dates"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dayMbajtje"
android:background="@drawable/border_bottom"
android:layout_weight="1"
android:textSize="@dimen/font_size"
android:gravity="center"
android:layout_marginRight="5dp"
android:text="12"
android:paddingBottom="@dimen/padding_spiner"
android:singleLine="true"
android:inputType="number"
android:imeOptions="actionNext"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/monthMbajtje"
android:background="@drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:textSize="@dimen/font_size"
android:layout_marginRight="5dp"
android:text="02"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/yearMbajtje"
android:background="@drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:textSize="@dimen/font_size"
android:text="2016"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="@dimen/general_margin"
android:layout_weight="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:text="Ora e mbajtjes:"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_marginTop="3dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hourMbajtje"
android:background="@drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:textSize="@dimen/font_size"
android:text="22"
android:paddingBottom="@dimen/padding_spiner"
android:singleLine="true"
android:inputType="number"
android:imeOptions="actionNext"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text=":"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/border_bottom"
android:layout_weight="1"
android:id="@+id/minutesMbajtje"
android:textSize="@dimen/font_size"
android:gravity="center"
android:text="20"
android:paddingBottom="@dimen/padding_spiner"
android:singleLine="true"
android:inputType="number"
android:imeOptions="actionNext"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_below="@+id/detajetMbajtjesText"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="@dimen/vertical_padding"
android:id="@+id/duttyCount"
android:visibility="gone">
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:id="@+id/duttyView"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center_vertical"
android:layout_marginRight="@dimen/margin_spiner"
android:text="Detyra e :"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/duttyCountS"
android:background="@drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:text="parë"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_alignParentRight="true"
android:id="@+id/checkboxPresentationLinear"
android:layout_height="wrap_content">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prezantim"
android:layout_gravity="right"
android:id="@+id/presentationDutty"
android:imeOptions="actionNext"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/duttyCount"
android:id="@+id/detajetMbajtjesPrezantimText"
android:orientation="horizontal"
android:visibility="gone"
android:showDividers="end">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="@dimen/general_margin"
android:layout_weight="3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:text="Data e prezantimit:"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:id="@+id/datesPresentation"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dayPresentation"
android:background="@drawable/border_bottom"
android:layout_weight="1"
android:textSize="@dimen/font_size"
android:gravity="center"
android:layout_marginRight="5dp"
android:text="12"
android:paddingBottom="@dimen/padding_spiner"
android:singleLine="true"
android:inputType="number"
android:imeOptions="actionNext"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/monthPresentation"
android:background="@drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:textSize="@dimen/font_size"
android:layout_marginRight="5dp"
android:text="02"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/yearPresentation"
android:background="@drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:textSize="@dimen/font_size"
android:text="2016"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="@dimen/general_margin"
android:layout_weight="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:text="Ora e prezantimit:"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_marginTop="3dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hourPresentation"
android:background="@drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:textSize="@dimen/font_size"
android:text="22"
android:paddingBottom="@dimen/padding_spiner"
android:singleLine="true"
android:inputType="number"
android:imeOptions="actionNext"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text=":"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/border_bottom"
android:layout_weight="1"
android:id="@+id/minutesPresentation"
android:textSize="@dimen/font_size"
android:gravity="center"
android:text="20"
android:paddingBottom="@dimen/padding_spiner"
android:singleLine="true"
android:inputType="number"
android:imeOptions="actionNext"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/psText"
android:layout_marginTop="@dimen/general_margin"
android:layout_below="@+id/detajetMbajtjesPrezantimText"
android:text="P.s."/>
<EditText
android:layout_width="match_parent"
android:layout_height="150dp"
android:inputType="textMultiLine"
android:id="@+id/psTextArea"
android:padding="@dimen/padding_spiner"
android:layout_below="@+id/psText"
android:layout_marginTop="@dimen/padding_spiner"
android:textSize="@dimen/font_size"
android:gravity="top"
android:background="@drawable/border_textarea"
android:imeOptions="actionDone"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/previewMbajtje"
android:layout_below="@+id/psTextArea"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>
我希望有人能告訴我如何優化這個XML代碼?
這是什麼慢?滾動?提交數據?還有別的嗎?你爲什麼認爲它的xml-你運行了哪些測試來確定緩慢的部分是什麼? (雖然一般來說 - 較低的視圖深度(較少的嵌套視圖)對繪製perf更快,並且您的嵌套深度相當)。 –
那麼當我點擊editTexts並寫入smth並隱藏鍵盤時,需要2或3秒才能隱藏鍵盤和鍵盤獲取全部白色的空間,持續2或3秒。 – ASTeam
好的,所以既然你有一個滾動視圖,你將在輸入法的adjustResize模式。是的,你的xml可能是這樣的原因,但不是它的繪圖性能 - 這可能是佈局性能。 –