MapView 和 Expandablelistview 滚动

MapView and Expandablelistview scrolling

我在使用 scrollview 和 nestedscrollview 时遇到了问题。 我尝试制作一个视图,其中顶部有一个地图,google 地图下方有一个可扩展的列表视图。我想滚动整个视图,这样 google 地图就好像是可扩展列表视图的一部分。

我的xml看起来像那样

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
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:id="@+id/htab_maincontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:theme="@style/WizyGeneralTheme"
tools:context=".fragments.ShoppingFragment">

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:fillViewport="true">

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

        <com.google.android.gms.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            />

        <ExpandableListView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/elv_shops"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:nestedScrollingEnabled="false"
            android:groupIndicator="@null"
            android:background="@color/white"/>
    </LinearLayout>


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

我尝试使用滚动视图,在此代码片段中尝试使用嵌套滚动视图,但两者均无效。 当我在可扩展列表视图中说 nestedScrollingEnabled=true 时,只有列表视图滚动但地图不滚动。你知道如何解决这个问题吗? 顺便说一下,我有一个类似的视图,但我使用的是 recyclerview 而不是 expandablelistview 并且效果很好。所以,我认为主要问题是可扩展列表视图,但我无法替换它,因为我的列表视图必须扩展。或者是否有可能绕过 expandablelistview?

也许您还需要我在可扩展列表视图中的项目的布局文件 组项目:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/section_shop_group"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">

<ImageView
    android:id="@+id/iv_shop"
    android:layout_width="140dp"
    android:layout_height="140dp"
    android:src="@mipmap/img_default"
    android:scaleType="centerCrop"
    android:layout_alignParentStart="true"/>

<RatingBar
    android:id="@+id/rb_shop"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:isIndicator="true"
    android:scaleX="1"
    android:scaleY="1"
    android:transformPivotX="0dp"
    android:transformPivotY="0dp"
    android:layout_marginVertical="15dp"
    android:layout_marginHorizontal="15dp"
    android:numStars="5"
    android:stepSize="0.1"
    android:theme="@style/WizyGeneralTheme.RatingBar"/>

<TextView
    android:id="@+id/tv_shop_name"
    android:layout_toRightOf="@id/iv_shop"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:maxLines="2"
    android:ellipsize="end"
    android:textStyle="bold"
    android:textSize="18dp"
    android:textColor="@color/black"
    android:layout_marginHorizontal="15dp"
    android:layout_marginTop="15dp"/>

<TextView
    android:id="@+id/tv_shop_address"
    android:layout_below="@id/tv_shop_name"
    android:layout_toRightOf="@id/iv_shop"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:maxLines="2"
    android:ellipsize="end"
    android:textSize="15dp"
    android:layout_marginHorizontal="15dp"/>

<TextView
    android:id="@+id/tv_shop_pricing"
    android:layout_toRightOf="@id/iv_shop"
    android:layout_alignParentBottom="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginHorizontal="15dp"
    android:layout_marginVertical="15dp"
    android:text="$$$$"
    android:textColor="@color/blue"
    />

<ImageView
    android:id="@+id/ivGroupIndicator"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/group_indicator"
    android:backgroundTint="@color/grey"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_marginTop="10dp"
    android:layout_marginRight="10dp"/>

</RelativeLayout>

组详细信息(扩展部分):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/section_shop_detail"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="10dp">

<TextView
    android:id="@+id/tv_opening_hours"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<ImageButton
    android:id="@+id/btn_shop_website"
    android:layout_toLeftOf="@id/btn_shop_route"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:scaleType="fitCenter"
    android:background="@drawable/rectangle_round_corners"
    android:backgroundTint="@color/white"
    android:src="@mipmap/ic_website"
    android:tint="@color/blue"
    android:layout_marginHorizontal="10dp"
    android:onClick="onShoppingWebsiteButtonClicked"/>

<ImageButton
    android:id="@+id/btn_shop_route"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:scaleType="fitCenter"
    android:background="@drawable/rectangle_round_corners"
    android:backgroundTint="@color/white"
    android:src="@mipmap/ic_navigation"
    android:tint="@color/blue"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_marginHorizontal="10dp"
    android:onClick="onShoppingMapsButtonClicked"/>

</RelativeLayout>

尝试只使用 ExpandableListView(没有 ScrollView,没有 MapView)。使用代码创建 MapView 并将其作为 header 添加到 ExpandableListView。另外,你可以添加这样的效果:http://android.amberfog.com/?p=915希望对你有帮助!