当在其下面添加一些小视图时,我的布局中的NestedScrollView变得缓慢

时间:2019-01-25 13:11:12

标签: java android android-recyclerview scrollview

我正在尝试为布局中的自定义底部导航栏添加一些图标,当我尝试添加它们时,占据大部分屏幕的NestedScrollView变得非常慢,滚动无法顺利进行只需添加一些图标,就可以实现触摸手势。 我不了解NestedScrollViews的这种行为。顺便说一下,它包含一个recyclerview。我在这里输入了布局代码。 bottom_layout包含一个视图组,其中包含四个图标大小的图像的视图组会导致此问题。如果我有1或2张图像,则完全没有问题。

编辑:如果可能的话,我想就加载列表作为滚动视图的子代的布局的一种好方法提出一些建议。

XML:

<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context=".activities.PlacesActivity">


<LinearLayout
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:layout_marginTop="22sp"
    android:background="#555555"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/place_toolbar_title"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="10dp"
        android:layout_weight="0.2"
        android:gravity="center_vertical"
        android:textColor="#f4e92c"
        android:textSize="21sp" />

    <!-- android:text="Cubbon Park" for the above textview-->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="0.9"
        android:gravity="center">

        <ImageView
            android:id="@+id/places_profile_button"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:layout_marginLeft="12dp"
            android:layout_marginTop="4sp"
            android:padding="5dp"

            android:src="@drawable/profile3x" />
    </LinearLayout>
</LinearLayout>

<android.support.v4.widget.NestedScrollView
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/bottom_layout"
    android:layout_below="@id/toolbar"
    android:fillViewport="true"
    app:layout_anchor="@id/toolbar"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

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


        <ImageView
            android:id="@+id/image_place_header"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:scaleType="centerCrop"

            />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:background="#ececef" />


        <android.support.v7.widget.CardView 

xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/map_card_place"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center">

            <LinearLayout
                android:id="@+id/map_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">


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


                    <ImageView
                        android:id="@+id/map_icon"
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:src="@drawable/location3x" />

                    <TextView
                        android:id="@+id/labelOnMap"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:layout_gravity="center_vertical"
                        android:gravity="center_vertical"
                        android:paddingLeft="5dp"
                        android:text="Point of Interest"
                        android:textColor="#757575"
                        android:textSize="20sp" />


                </LinearLayout>


                <fragment xmlns:android="http://schemas.android.com

/apk/res/android"
                    xmlns:tools="http://schemas.android.com/tools"
                    android:id="@+id/map"


android:name="com.testapp.android.WorkaroundMapFragment"
                    android:layout_width="match_parent"
                    android:layout_height="170dp"


tools:context="com.example.googlemap.MapsActivity" />
            </LinearLayout>

        </android.support.v7.widget.CardView>

        <!--recyclerview containing all the content-->
        <android.support.v7.widget.RecyclerView
            android:id="@+id/metadata"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


    </LinearLayout>

</android.support.v4.widget.NestedScrollView>


<include
    android:id="@+id/bottom_layout"
    layout="@layout/bottom_bar"
    android:layout_width="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_height="40dp" />

<ImageButton
    android:id="@+id/fab_main"
    android:layout_width="62dp"
    android:layout_height="62dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:background="?attr/selectableItemBackgroundBorderless"
    android:scaleType="fitCenter"
    android:src="@drawable/btn_scan_large" />



</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

我发现消除呆滞的解决方案是将图像放置在drawable-nodpi文件夹中。

在这里找到此答案很有帮助:

https://stackoverflow.com/a/51960548/10165076

相关问题