2016-07-28 80 views
1

我試圖實現像GoogleMap全屏幕布局和ViewPager在底部的功能。谷歌地圖與ViewPager在底部,ViewPagerFragment項目全屏滾動

現在ViewPager最初將在底部,用戶可以垂直滾動,如果它的內容高度大。用戶應該能夠以全屏方式進行滾動(根據下面的演示圖像,可以從底部到頂部切換到ViewPager的頁面項目高度)。

目前,我可以通過ScrollView(with match_parnt height and paddingTop like 380dp)在ViewPager的片段(佈局代碼如下)中獲得相同的UI效果。

現在我現在面臨的問題是GoogleMap由於ViewPager片段的match_parent高度而沒有響應任何觸摸/點擊事件。

我的預期結果是GoogleMap必須能夠監聽觸摸/點擊事件,ViewPager的片段必須可以從底部到頂部方向垂直滾動。

我在搜索過程中發現我們可以使用requestDisallowInterceptTouchEvent使子視圖來監聽這些觸摸/點擊事件。但在我的情況下ViewPager和ScrollView裏面的片段正在採取所有的觸摸/點擊事件。

片編,

activity.xml

<FrameLayout 
    ... 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <fragment 
     ... 
      android:name="com.google.android.gms.maps.SupportMapFragment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      ... /> 

     <android.support.v7.widget.Toolbar 
      ... 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      ... /> 

     <android.support.v4.view.ViewPager 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
</FrameLayout> 

viewpager_fragment_item.xml

<ScrollView 
    ... 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    ... > 

    <LinearLayout 
     ... 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:paddingTop="380dp" > 

    <!-- 
      child views in here. 
     --> 
    </LinearLayout> 
</ScrollView> 

預計輸出演示

Expected output demo

在本演示中,用戶可以觸摸,放大/縮小Map,可以滑動ViewPager和滾動ViewPager的Fragemt全屏顯示。所以,這就是我想要達到的目標。

如果有人給予有用的鏈接或一些演示,我將不勝感激。

請幫忙!

感謝。

回答

0

好,使用BottomSheet佈局解決它

讓我告訴你我的一片的佈局代碼完全理解它。

<android.support.design.widget.CoordinatorLayout 
    ... 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    ... > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <fragment xmlns:map="http://schemas.android.com/apk/res-auto" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:name="com.google.android.gms.maps.SupportMapFragment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      .... /> 

     <!-- Other layout component code like Toolbar--> 

    </RelativeLayout> 

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/bottomSheet" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 

     <android.support.v4.view.ViewPager 
      ... 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      ... /> 
    </android.support.v4.widget.NestedScrollView> 
</android.support.design.widget.CoordinatorLayout> 

而在您的java文件中,您需要將peek高度設置爲bottomomsheet佈局。

View bottomSheet = findViewById(R.id.bottomSheet); 
    mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); 
    mBottomSheetBehavior.setPeekHeight(300); 
    mBottomSheetBehavior.setHideable(false); 
    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_DRAGGING); 

我做了一個演示是很好,你可以找到它here.