2012-07-17 110 views
1

我得到这样的问题:我有一个MapView和它下面的ListView。地图大小是固定的。但我需要一起滚动我的观点。我以某种方式处理了非滚动地图和单迭代列表的问题,但另一个出现了 - 在ScrollView中ListView下面有很多可用空间,我无法摆脱它。我认为将列表设置为“wrap_content”会有所帮助,但事实并非如此。 怎么办? 这里是我的布局:滚动视图不包裹其内容

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/scrollView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fillViewport="true"> 

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <com.package.MyMapView 
        android:layout_width="match_parent" 
        android:layout_height="100dp" 
        android:clickable="true" 
        android:apiKey="key" 
        android:id="@+id/map" 
        android:layout_gravity="top"/> 
     <ListView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/channelsList" > 

     </ListView> 

    </LinearLayout> 

    </ScrollView> 
</LinearLayout> 

回答

2

它始终不是一个好主意来包装的ListViewScrollView,因为它们都是可滚动的视图。

+0

我知道。这样的答案有很多问题,但我不问它是否是一个好主意,我只是有一个我必须达成的目标。目标是:我需要一个带有地图和列表的“页面”,它们应该可以一起滚动。 – Graykos 2012-07-17 09:15:55

+0

所以如果你滚动地图,列表也滚动? – waqaslam 2012-07-17 09:26:51

+0

nope。在滚动视图中有两个视图。我需要滚动地图来查看它。但是当我向下滚动列表时,我需要地图以列表滚动的方式离开屏幕。 – Graykos 2012-07-17 09:37:06

1

你可以尝试替换这些行:这些行

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" > 
+1

我试过 - 没有任何改变。 – Graykos 2012-07-17 09:16:33

+0

fill_parent被match_parent取代。它意味着相同,但应该使用后者。 – Pijusn 2012-08-01 10:53:11

1

不要在ScrollView中插入任何ListViews,在任何情况下都不会满足您的要求。尝试将MapView作为标题添加到ListView中,使其与列表一起滚动。

要在您的java代码中实现mapView作为标题,只需将addHeaderView(<your_map_view>)包含到listView组件中即可。这应该在调用setAdapter()之前调用。

+0

我试过了,但我无法将地图添加为标题。现在我得到了地图和列表,他的问题是:在我的列表下面有很多空的空间。哪(如我所料)不应该在那里 – Graykos 2012-07-17 10:18:50