2013-08-28 18 views
7

這是iOS的this相當於iOS的問題。Android - 類似於foursquare的ScrollView +地圖+列表

嘗試創建一個視圖,該視圖包含大約20%的屏幕上的MapView(在ActionBar下...),而其餘的屏幕是滾動視圖,當向下滾動時,疊加在MapView頂部並隱藏它。總之就像FourSquare的Android應用程序。 任何想法?

+0

[http://stackoverflow.com/questions/25487861/android-maps-markers-bounds-at-the-center-of-top-half-of-map-area](http://stackoverflow.com/questions/25487861/android-maps-markers-bound-top-half-of-map-area的中心) –

回答

0

您可以在XML剛剛宣佈提交ScrollView嵌入一個LinearLayout,嵌入一個MapView

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center_horizontal" 
    android:fillViewport="true" > 

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

     <fragment 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      class="com.google.android.gms.maps.MapFragment" /> 

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

     ...... Your list and other stuff ....... 

     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 

然後你就可以通過指定layout_weight屬性

設置每個元素的大小編輯 IvanDanDo,在我們的討論後,我發現這個鏈接,可能做你想做的(不知道,但我沒有嘗試它):Android: Have an arbitrary View slide under another View like the software keyboard does

+0

試過了,給了'MapFragment'' layout_weight' = 1和'LinearLayout' 'layout_weight' = 3,但我看到的只是整個屏幕上的地圖,底部的地圖,列表提示......並且它也不會在我的地圖頂部滾動。 – OferM

+0

這很奇怪,我的應用程序中有幾乎相同的代碼。例如,如果您用「ImageView」替換地圖,它會滾動嗎?另外,你可以嘗試在第一個'LinearLayout'中指定'weightSum'屬性爲4嗎? – jbihan

+0

好吧,所以將它改爲'ImageView',我意識到我的列表不夠大,所以不需要滾動。 (啞)。但是現在當我滾動時,'ImageView' /'Map'只是滾動起來,我希望它粘在頂部,因爲列表最終會像重疊一樣滾動並完全隱藏它。我如何得到這種效果? – OferM

4

最後更新

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:map="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity" > 

<fragment 
    android:id="@+id/map_fragment" 
    android:name="com.myapp.MapFragment" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" /> 

<fragment 
    android:id="@id/list_fragment" 
    android:name="com.myapp.ListFragment" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" /> 

然後我一種無形的頭添加到列表,像這樣:

@Override 
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    super.onCreateView(inflater, container, savedInstanceState); 

    View view = inflater.inflate(R.layout.listview, container, false); 
    SwipeListView listView = (SwipeListView) view.findViewById(R.id.venue_list); 

    // An invisible view added as a header to the list and clicking it leads to the mapfragment 
    TextView invisibleView = new TextView(inflater.getContext()); 
    invisibleView.setBackgroundColor(Color.TRANSPARENT); 
    invisibleView.setHeight(300); 
    invisibleView.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      listener.moveToMapFragment(); 
                     } 
    }); 
    listView.addHeaderView(invisibleView); 

其實這也沒什麼理想,但它的工作原理。我希望它可以幫助別人..

+1

:如果你有更好的解決方案,請讓我知道 – user965071

+0

這仍然是我發現的最好的解決方案。我在不可見的框架上添加了一個點擊處理程序,打開地圖以適應整個屏幕。 – OferM

+0

你能分享你創建的佈局嗎? – user965071

1

的最簡單的解決方案是一個餘量添加到滑塊內容(SlidingUpPanel的第二個參數),然後取下衰落背景。所有這些都是從XML完成的。

相關問題