问题描述
我在使用scrollview和nestedscrollview时遇到麻烦.我尝试做一个视图,在顶部的地图上,在谷歌地图的下方,有一个可扩展的listview.而且我想滚动查看整个视图,就像Google地图是expandablelistview的一部分.
I have troubles with scrollview and nestedscrollview.I try to make a view where on the top there is a map and below the google map there is a expandable listview. And I want to scroll through the whole view so it's like that the google map is a part of the expandablelistview.
我的xml看起来像这样
My xml looks like that
<?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>
我尝试使用滚动视图,并且在此代码段中使用了nestedscrollview,但两者均无法正常工作.当我说在expandablelistview上nestedScrollingEnabled = true时,只有列表视图滚动,而不是地图滚动.你有解决的办法吗?顺便说一句,我有一个相似的视图,但是在这里我使用了一个recyclerview而不是expandablelistview,这很好用.所以,我认为主要问题是expandablelistview,但是我不能替换它,因为我的listview必须扩展.还是有可能绕过expandablelistview?
I tried to use a scrollview and in this code snippet a nestedscrollview but both didn't work.When i say that nestedScrollingEnabled=true at the expandablelistview only the listview scrolls but not the map. Do you have any idea how to solve this?By the way, I have a similar view but there I use a recyclerview instead of the expandablelistview and this works fine. So, I think the main problem is the expandablelistview but I can't replace this because my listview has to expand. Or is there any possibility to bypass the expandablelistview?
也许您还需要在expandablelist视图中从我的商品中获取布局文件组项目:
Maybe you need also the layout files from my item in the expandablelistviewGroup Item:
<?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>
组详细信息(扩展部分):
Group Detail (expanded part):
<?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并将其作为标头添加到ExpandableListView中.此外,您可以添加如下效果: http://android.amberfog.com/?p= 915 希望能有所帮助!
Try just have the ExpandableListView (No ScrollView, No MapView). Use code to create the MapView and add it to the ExpandableListView as header. In addition, you may add effect like this: http://android.amberfog.com/?p=915 Hope that helps!
这篇关于MapView和Expandablelistview滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!