Emulator 运行 到达特定布局时速度较慢

Emulator run slowly when come to a specific layout

我不知道我的 xml 布局有什么问题。每当它打算 AddMoreClaims activity 时,我的模拟器都会 运行 缓慢并且有时不响应,如下图所示。

这是 logCat 消息

12-09 05:05:59.758    2688-2688/? E/RichInputConnection﹕ Unable to connect to the editor to retrieve text.
12-09 05:05:59.758    2688-2688/? W/RichInputConnection﹕ Unable to connect to the editor. Setting caps mode without knowing text.
12-09 05:05:59.760    2688-2688/? I/Choreographer﹕ Skipped 352 frames!  The application may be doing too much work on its main thread.
12-09 05:05:59.783    2688-2710/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
12-09 05:05:59.784    2688-2710/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa30bfe80, error=EGL_SUCCESS
12-09 05:06:03.080    2808-2808/? I/Choreographer﹕ Skipped 153 frames!  The application may be doing too much work on its main thread.
12-09 05:06:08.163    2808-2808/? I/Choreographer﹕ Skipped 151 frames!  The application may be doing too much work on its main thread.
12-09 05:06:10.863    2808-2808/? I/Choreographer﹕ Skipped 161 frames!  The application may be doing too much work on its main thread.

xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:fillViewport="true"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@mipmap/dark_blue"
        android:weightSum="1">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Enter Claims Information"
            android:id="@+id/textViewClaims"
            android:paddingTop="30sp"
            android:textSize="20dp"
            android:paddingLeft="15sp"
            android:textColor="@color/white"
            android:layout_weight="0.05" />

        <View
            android:layout_marginLeft="10dp"
            android:layout_width="340sp"
            android:layout_height="2dp"
            android:background="#c0c0c0"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Claims Type : "
            android:paddingTop="20sp"
            android:paddingLeft="15sp"
            android:textSize="17dp"
            android:textColor="@color/white"
            android:id="@+id/textViewClaimsType"
            android:layout_weight="0.05" />

        <Spinner
            android:layout_width="308dp"
            android:layout_marginLeft="10dp"
            android:background="@color/light_gray"
            android:layout_height="48dp"
            android:id="@+id/spinner" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Claims Amount :"
            android:paddingTop="20sp"
            android:paddingLeft="15sp"
            android:textSize="17dp"
            android:textColor="@color/white"
            android:id="@+id/textViewAmount"
            android:layout_weight="0.05" />

        <EditText
            android:layout_width="308dp"
            android:layout_height="wrap_content"
            android:layout_margin="10sp"
            android:background="@drawable/round_corner_square"
            android:id="@+id/editTextAmount"
            android:paddingLeft="20dp"
            android:layout_weight="0.09" />


            <ImageView
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"
                android:layout_marginTop="20dp"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:id="@+id/imageView" />


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add picture"
            android:id="@+id/button"
            android:layout_gravity="center_horizontal"
            android:layout_weight="0.05" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Enter Description"
            android:paddingTop="30sp"
            android:paddingLeft="15sp"
            android:textSize="17dp"
            android:textColor="@color/white"
            android:id="@+id/textView12"
            android:layout_weight="0.05" />

        <EditText
            android:layout_width="308dp"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="@drawable/round_corner_square"
            android:layout_weight="0.12"
            android:paddingLeft="20dp"
            android:paddingBottom="80dp"
            android:layout_x="14dp"
            android:layout_y="146dp"
            android:id="@+id/textDescription" />

        <Button
            android:layout_width="159dp"
            android:layout_height="wrap_content"
            android:text="save"
            android:layout_marginTop="20dp"
            android:id="@+id/button1"
            android:layout_gravity="center_horizontal"
            android:layout_weight="0.05" />


    </LinearLayout>
</ScrollView>

为什么会发生这种情况,我该如何解决?谢谢

 The application may be doing too much work on its main thread.

Layouts are a key part of Android applications that directly affect the user experience. If implemented poorly, your layout can lead to a memory hungry application with slow UIs. The Android SDK includes tools to help you identify problems in your layout performance, which when combined the lessons here, you will be able to implement smooth scrolling interfaces with a minimum memory footprint.

按需加载视图

Beyond simply including one layout component within another layout, you might want to make the included layout visible only when it's needed, sometime after the activity is running. This lesson shows how you can improve your layout's initialization performance by loading portions of your layout on demand.

错误的概念

 <ImageView
            android:layout_gravity="center"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:layout_marginTop="20dp"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:id="@+id/imageView" />


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Add picture"
        android:id="@+id/button"
        android:layout_gravity="center_horizontal"
        android:layout_weight="0.05" />

这里你用的是android:layout_weight,嗯。然后另一种情况你设置了Hard coded height & Width,这就是为什么有问题。避免硬编码值。