NestedScrollView в моем макете становится вялым, когда под ним добавлено еще несколько небольших представлений - PullRequest
0 голосов
/ 25 января 2019

Я пытаюсь добавить несколько значков для пользовательской нижней панели навигации в свой макет, и когда я пытался добавить их, 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 голосов
/ 27 февраля 2019

Я обнаружил, что решением для устранения медлительности было просто поместить изображения в папку drawable-nodpi.

нашел этот ответ полезным:

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

...