当来到一个特定的布局仿真器运行缓慢 [英] Emulator run slowly when come to a specific layout

查看:594
本文介绍了当来到一个特定的布局仿真器运行缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这有什么错我的 XML 布局。每次当它意图 AddMoreClaims 活动,我的模拟器会运行缓慢,有时没有响应,如下图所示的图像。

在这里输入的形象描述

这是的logcat 的消息

  5月12日至九日:05:59.758 2688年至2688年/? E / RichInputConnection:无法连接到编辑器来检索文本。
5月12日至9日:05:59.758 2688年至2688年/? W / RichInputConnection:无法连接到编辑器。不知道文本设置大写模式。
5月12日至9日:05:59.760 2688年至2688年/? I /编舞:跳过352帧!该应用程序可能会做它的主线程的工作太多了。
5月12日至9日:05:59.783 2688至2710年/? W / EGL_emulation:eglSurfaceAttrib没有实现
5月12日至9日:05:59.784 2688至2710年/? W / OpenGLRenderer:无法设置EGL_SWAP_BEHAVIOR表面0xa30bfe80错误= EGL_SUCCESS
5月12日至9日:06:03.080 2808至08年/? I /编舞:跳过153帧!该应用程序可能会做它的主线程的工作太多了。
5月12日至9日:06:08.163 2808至08年/? I /编舞:跳过151帧!该应用程序可能会做它的主线程的工作太多了。
5月12日至9日:06:10.863 2808至08年/? I /编舞:跳过161帧!该应用程序可能会做它的主线程的工作太多了。

XML

 <?XML版本=1.0编码=UTF-8&GT?;
<滚动型
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_weight =1
    机器人:fillViewport =真
    机器人:方向=垂直
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>    < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:方向=垂直的android:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:背景=@的mipmap / dark_blue
        机器人:weightSum =1>
        <的TextView
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:textAppearance =机器人:ATTR / textAppearanceLarge
            机器人:文字=输入理赔信息
            机器人:ID =@ + ID / textViewClaims
            机器人:paddingTop =30sp
            机器人:TEXTSIZE =20dp
            机器人:paddingLeft =15sp
            机器人:文字颜色=@色/白
            机器人:layout_weight = /&GT0.05;        <查看
            机器人:layout_marginLeft =10dp
            机器人:layout_width =340sp
            机器人:layout_height =2DP
            机器人:背景=#C0C0C0/>        <的TextView
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:textAppearance =机器人:ATTR / textAppearanceLarge
            机器人:文字=索赔类型:
            机器人:paddingTop =20SP
            机器人:paddingLeft =15sp
            机器人:TEXTSIZE =17dp
            机器人:文字颜色=@色/白
            机器人:ID =@ + ID / textViewClaimsType
            机器人:layout_weight = /&GT0.05;        <微调
            机器人:layout_width =308dp
            机器人:layout_marginLeft =10dp
            机器人:背景=@彩色/ light_gray
            机器人:layout_height =48dp
            机器人:ID =@ + ID /微调/>        <的TextView
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:textAppearance =机器人:ATTR / textAppearanceLarge
            机器人:文字=索赔金额:
            机器人:paddingTop =20SP
            机器人:paddingLeft =15sp
            机器人:TEXTSIZE =17dp
            机器人:文字颜色=@色/白
            机器人:ID =@ + ID / textViewAmount
            机器人:layout_weight = /&GT0.05;        <的EditText
            机器人:layout_width =308dp
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_margin =10SP
            机器人:背景=@绘制/ round_corner_square
            机器人:ID =@ + ID / editTextAmount
            机器人:paddingLeft =20dp
            机器人:layout_weight =0.09/>
            < ImageView的
                机器人:layout_gravity =中心
                机器人:adjustViewBounds =真
                机器人:scaleType =fitXY
                机器人:layout_marginTop =20dp
                机器人:layout_width =200dp
                机器人:layout_height =200dp
                机器人:ID =@ + ID / ImageView的/>
        <按钮
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字=添加图片
            机器人:ID =@ + ID /按钮
            机器人:layout_gravity =CENTER_HORIZONTAL
            机器人:layout_weight = /&GT0.05;        <的TextView
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:textAppearance =机器人:ATTR / textAppearanceLarge
            机器人:文字=输入内容
            机器人:paddingTop =30sp
            机器人:paddingLeft =15sp
            机器人:TEXTSIZE =17dp
            机器人:文字颜色=@色/白
            机器人:ID =@ + ID / textView12
            机器人:layout_weight = /&GT0.05;        <的EditText
            机器人:layout_width =308dp
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_margin =10dp
            机器人:背景=@绘制/ round_corner_square
            机器人:layout_weight =0.12
            机器人:paddingLeft =20dp
            机器人:paddingBottom会=80dp
            机器人:layout_x =14dp
            机器人:layout_y =146dp
            机器人:ID =@ + ID / textDescription/>        <按钮
            机器人:layout_width =159dp
            机器人:layout_height =WRAP_CONTENT
            机器人:文字=拯救
            机器人:layout_marginTop =20dp
            机器人:ID =@ + ID /按钮1
            机器人:layout_gravity =CENTER_HORIZONTAL
            机器人:layout_weight = /&GT0.05;
    < / LinearLayout中>
< /滚动型>

为什么会出现这种情况,我该如何解决呢?谢谢


解决方案

 应用程序可能会做它的主线程的工作太多了。


  

布局是直接影响Android应用程序的重要组成部分
  用户体验。如果执行不力,你的布局可能导致
  内存饿应用缓慢的UI。 Android SDK还
  工具来帮助您识别布局的表现,其中的问题
  当结合这里的教训,你将能够实现平稳
  滚动接口,用最少的内存占用。


加载浏览点播


  

除了简单地包括另一个布局中的一个布局组件,
  你可能想使纳入布局可见,只有当它的
  需要的话,该活动运行后的某个。本课程介绍了如何
  可以提高通过加载布局的初始化性能
  您的需求,布局的部分。


错误的概念

 < ImageView的
            机器人:layout_gravity =中心
            机器人:adjustViewBounds =真
            机器人:scaleType =fitXY
            机器人:layout_marginTop =20dp
            机器人:layout_width =200dp
            机器人:layout_height =200dp
            机器人:ID =@ + ID / ImageView的/>
    <按钮
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=添加图片
        机器人:ID =@ + ID /按钮
        机器人:layout_gravity =CENTER_HORIZONTAL
        机器人:layout_weight = /&GT0.05;

在这里,你正在使用的android:layout_weight ,好。然后你设置硬codeD &高度功放另一种情况;宽度,这就是为什么有问题。避免用力codeD值。

I don't know what's wrong with my xml layout. Everytime when it intent to AddMoreClaims activity, my emulator will run slowly and sometimes not responding as image shown below.

And this are the logCat message

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>

Why would this happen and how can I solve it ? Thanks

解决方案

 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.

Loading Views On Demand

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.

Wrong Concept

 <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" />

In here you are using android:layout_weight, Well .Then another case you set Hard coded height & Width ,That's why have problem . Avoid Hard coded Value .

这篇关于当来到一个特定的布局仿真器运行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆