当前位置: 首页 > 知识库问答 >
问题:

ScrollView在滚动android上滞后太多

宋洲
2023-03-14

我在线性布局中使用滚动视图,问题是布局响应正常,一旦我开始滚动,它就会滞后太多。

< LinearLayout > 
< ScrollView >
< Linearlayout >..sub (LinearLayout)..< /LinearLayout >
< ScrollView>
< LinearLayout> 



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    android:background="@drawable/round_edittext"
    >

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/pddd"
                >


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

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

            <TextView
                android:id="@+id/profile_user_email_id"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:clickable="true"
                android:textAlignment="center"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#000"
                android:textSize="25sp"
                android:textStyle="bold"

                />


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Complete Your profile"
                android:textAlignment="center"
                android:textColor="#000"
                android:textSize="25sp"
                android:textStyle="bold" />


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10sp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Name   :"
                    android:textColor="#000"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <EditText
                    android:id="@+id/profileActivity_student_id"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10sp"
                    android:background="@drawable/round_edittext"
                    android:inputType="textCapSentences"
                    android:textColor="#000"
                    android:textSize="25sp"
                    android:textStyle="bold"

                    />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10sp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Mobile : "
                    android:textColor="#000"
                    android:textSize="20sp"
                    android:textStyle="bold" />


                <EditText
                    android:id="@+id/profileActivity_student_mobile_id"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5sp"
                    android:background="@drawable/round_edittext"
                    android:inputType="number"
                    android:maxLength="10"
                    android:textColor="#000"
                    android:textSize="25sp"
                    android:textStyle="bold"

                    />
            </LinearLayout>


            <RadioButton
                android:id="@+id/profile_faculty_radio_id"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20sp"
                android:layout_marginTop="20sp"
                android:text="Faculty"
                android:textColor="#000"
                android:textSize="20sp"
                android:textStyle="bold" />


            <RadioButton
                android:id="@+id/profile_parents_radio_id"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20sp"
                android:layout_marginTop="10sp"
                android:text="Parents"
                android:textColor="#000"
                android:textSize="20sp"
                android:textStyle="bold"

                />


            <LinearLayout
                android:id="@+id/layout_faculty_key_profile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10sp"
                android:orientation="horizontal"
                android:visibility="visible"
                android:weightSum="6">

                <TextView
                    android:layout_width="0sp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Key :"
                    android:textColor="#000"
                    android:textSize="20sp"
                    android:textStyle="bold"

                    />

                <EditText
                    android:id="@+id/pff_key"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10sp"
                    android:layout_weight="3"
                    android:background="@drawable/round_edittext"
                    android:inputType="text|textNoSuggestions"
                    android:textColor="#000"
                    android:textSize="30sp"
                    android:textStyle="bold" />

                <ImageView
                    android:id="@+id/faculty_verify_bt_id"
                    android:layout_width="0sp"
                    android:layout_height="50sp"
                    android:layout_weight="1"
                    android:background="@drawable/check"
                    android:textColor="#000"
                    android:textStyle="bold"

                    />

                <ImageView
                    android:id="@+id/faculty_cancle_bt_id"
                    android:layout_width="0sp"
                    android:layout_height="50sp"
                    android:layout_weight="1"
                    android:background="@drawable/minus1"
                    android:textColor="#000"
                    android:textStyle="bold" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:id="@+id/proile_activity_unique_key_linearlayout_id"

                >

                <TextView
                    android:layout_width="0sp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Key :"
                    android:textColor="#000"
                    android:textSize="20sp"
                    android:textStyle="bold"

                    />

                <EditText
                    android:id="@+id/profile_activity_school_key"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10sp"
                    android:layout_weight="3"
                    android:background="@drawable/round_edittext"
                    android:inputType="text|textNoSuggestions"
                    android:textColor="#000"
                    android:textSize="30sp"
                    android:textStyle="bold"


                    />

                <ImageView
                    android:id="@+id/profile_activity_school_key_verify_bt_id"
                    android:layout_width="0sp"
                    android:layout_height="50sp"
                    android:layout_weight="1"
                    android:background="@drawable/check"
                    android:textColor="#000"
                    android:textStyle="bold"

                    />

                <ImageView
                    android:id="@+id/profile_activity_school_key_cancle_bt_id"
                    android:layout_width="0sp"
                    android:layout_height="50sp"
                    android:layout_weight="1"
                    android:background="@drawable/minus1"
                    android:textColor="#000"
                    android:textStyle="bold" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                    android:layout_marginTop="20sp"
                    android:orientation="horizontal"

                >


                <Spinner
                    android:id="@+id/activityprofile_spinner_id"
                    android:layout_width="200sp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="50sp"
                    >
                </Spinner>


            </LinearLayout>


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

                <Button
                    android:id="@+id/profile_saveinfo_id"
                    android:layout_width="100sp"
                    android:layout_height="50sp"
                    android:layout_gravity="center_horizontal"
                    android:background="@drawable/save2" />

                <Button
                    android:id="@+id/profile_nagivate_id"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:text="Navigate" />
            </LinearLayout>

        </LinearLayout>
    </LinearLayout>
   </ScrollView>
</LinearLayout>

我在我的线性布局中使用了这段代码,一旦我触摸了RadiButton或edittext或我向下滚动,它就开始滞后很多。我无法理解这个问题,我使用的图像尺寸小于100kb

共有1个答案

东典
2023-03-14

我编辑了你的代码,取出了大约4个不必要的LinearLayouts。请测试它的性能。如果仍然很慢,尝试用@IshitaShinha建议的RelativeLayouts替换剩余的垂直LinearLayouts。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/round_edittext"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/pddd"
        android:orientation="vertical">

        <TextView
            android:id="@+id/profile_user_email_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:clickable="true"
            android:textAlignment="center"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000"
            android:textSize="25sp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Complete Your profile"
            android:textAlignment="center"
            android:textColor="#000"
            android:textSize="25sp"
            android:textStyle="bold" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10sp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Name   :"
                android:textColor="#000"
                android:textSize="20sp"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/profileActivity_student_id"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10sp"
                android:background="@drawable/round_edittext"
                android:inputType="textCapSentences"
                android:textColor="#000"
                android:textSize="25sp"
                android:textStyle="bold" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10sp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Mobile : "
                android:textColor="#000"
                android:textSize="20sp"
                android:textStyle="bold" />


            <EditText
                android:id="@+id/profileActivity_student_mobile_id"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5sp"
                android:background="@drawable/round_edittext"
                android:inputType="number"
                android:maxLength="10"
                android:textColor="#000"
                android:textSize="25sp"
                android:textStyle="bold" />
        </LinearLayout>

        <RadioButton
            android:id="@+id/profile_faculty_radio_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20sp"
            android:layout_marginTop="20sp"
            android:text="Faculty"
            android:textColor="#000"
            android:textSize="20sp"
            android:textStyle="bold" />

        <RadioButton
            android:id="@+id/profile_parents_radio_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20sp"
            android:layout_marginTop="10sp"
            android:text="Parents"
            android:textColor="#000"
            android:textSize="20sp"
            android:textStyle="bold" />


        <LinearLayout
            android:id="@+id/layout_faculty_key_profile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10sp"
            android:orientation="horizontal"
            android:visibility="visible"
            android:weightSum="6">

            <TextView
                android:layout_width="0sp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Key :"
                android:textColor="#000"
                android:textSize="20sp"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/pff_key"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10sp"
                android:layout_weight="3"
                android:background="@drawable/round_edittext"
                android:inputType="text|textNoSuggestions"
                android:textColor="#000"
                android:textSize="30sp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/faculty_verify_bt_id"
                android:layout_width="0sp"
                android:layout_height="50sp"
                android:layout_weight="1"
                android:background="@drawable/check"
                android:textColor="#000"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/faculty_cancle_bt_id"
                android:layout_width="0sp"
                android:layout_height="50sp"
                android:layout_weight="1"
                android:background="@drawable/minus1"
                android:textColor="#000"
                android:textStyle="bold" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/proile_activity_unique_key_linearlayout_id"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="0sp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Key :"
                android:textColor="#000"
                android:textSize="20sp"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/profile_activity_school_key"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10sp"
                android:layout_weight="3"
                android:background="@drawable/round_edittext"
                android:inputType="text|textNoSuggestions"
                android:textColor="#000"
                android:textSize="30sp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/profile_activity_school_key_verify_bt_id"
                android:layout_width="0sp"
                android:layout_height="50sp"
                android:layout_weight="1"
                android:background="@drawable/check"
                android:textColor="#000"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/profile_activity_school_key_cancle_bt_id"
                android:layout_width="0sp"
                android:layout_height="50sp"
                android:layout_weight="1"
                android:background="@drawable/minus1"
                android:textColor="#000"
                android:textStyle="bold" />
        </LinearLayout>

        <Spinner
            android:id="@+id/activityprofile_spinner_id"
            android:layout_width="200sp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50sp"
            android:layout_marginTop="20sp" />

        <Button
            android:id="@+id/profile_saveinfo_id"
            android:layout_width="100sp"
            android:layout_height="50sp"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/save2" />

        <Button
            android:id="@+id/profile_nagivate_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Navigate" />
    </LinearLayout>
</ScrollView>
 类似资料:
  • 到这里基本上你已经掌握了 Android 所有的常用控件,不知道有没有这样的疑惑:如果控件太多,在有的小尺寸手机上将屏幕占满了怎么办?是不是有一种通用的解决方法?没错,本节的主角——ScrollView 就是来帮你解决这个问题的,它让你的控件能够在屏幕显示不足的情况下,支持滚动展示。 1. ScrollView 的特性 ScrollView 是一种可以有效解决由于 View 过多显示不全的布局,它

  • 我刚刚实现了库图表(https://github.com/danielgindi/Charts)在tableview中,当我的图表包含大量数据时,我在滚动过程中遇到了很大的延迟。 我在ChartTableViewCell中有一个方法,我在其中根据从我的视图控制器传递和调用的数据绘制图表。 在我的tableViewController中,我在解析数据后调用函数: 我错过了什么?因为滚动时视图滞后得很

  • 我正在使用嵌套的RecycerView。意思是在一个垂直的回收器视图中,我有多个水平的回收器视图 }

  • 主要内容:本节引言:,可能遇到的一些需求,本节小结:本节引言: 本节带来的是Android基本UI控件中的第十个:ScrollView(滚动条),或者我们应该叫他 竖直滚动条,对应的另外一个水平方向上的滚动条:HorizontalScrollView,先来一发官方文档 的链接:ScrollView,我们可以看到类的结构如下: 嘿嘿,原来是一个FrameLayout的容器,不过在他的基础上添加了滚动,允许显示的比实际多的内容! 另外,只能够往里面放置

  • 可以水平和垂直两个方向翻页滚动的ScrollView,用的是atpagingview。 [Code4App.com]

  • 问题内容: 我box-shadow最近在页面的一部分中添加了,以为其提供与Mac OS X应用程序相同的阴影边框效果。看起来不错,但我注意到在页面上上下滚动会使其滞后。我通常只会在页面上贴满恼人的背景图像,大量图像和嵌入视频(咳嗽MySpace咳嗽)的页面上看到此图像。我最初决定使用box-shadow,因为我发现它可以消除使用图像的需要,从而消除滚动滞后的可能性。 我知道CSS3仍然是新的,但这