2017-04-05 25 views
0

我使用下面庫:https://github.com/umano/AndroidSlidingUpPanelAndroid的 - umano SlidingUpPanelLayout - 內容fitsSystemWindows

我想滾動時,顯示如下狀態欄的事情,我不能讓main_content(在SlidingUpPanelLayout的第一容器)適合屏幕。滾動時,我想在狀態欄下方顯示內容。

這是我的第一個XML配置:

<android.support.v4.widget.DrawerLayout 
    ... 
    android:fitsSystemWindows="true"> 

    <com.hnhh.app3.fragments.model.FitsSystemWindowsFrameLayout 
     ... 
     android:fitsSystemWindows="true"> 

     <!-- This is where I don't get what I want, 
      This container has always a padding top equals to the 
      status bar size, so it will always affect the direct 
      childs => main_content (my fragments container) --> 
     <com.sothree.slidinguppanel.SlidingUpPanelLayout 
      android:id="@+id/sliding_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" // seems to not be supported 
      android:gravity="bottom" 
      ...> 

      <!-- Main content - fragments placeholder --> 
      <com.hnhh.app3.fragments.model.FitsSystemWindowsFrameLayout 
       android:id="@+id/main_content" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true" // if the parent doesn't it will not either. 
       tools:background="@color/colorAccent" /> 

      <!-- Panel  --> 
      <FrameLayout 
       android:id="@+id/..." 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:clickable="true" 
       android:fitsSystemWindows="false" /> 
     </com.sothree.slidinguppanel.SlidingUpPanelLayout> 

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

      <com.hnhh.app3.widgets.BannerAdWrapper.../> 
     </FrameLayout> 

    </com.hnhh.app3.fragments.model.FitsSystemWindowsFrameLayout> 

    <include layout="@layout/navigation" /> 

</android.support.v4.widget.DrawerLayout> 

我試圖與幾個父母爲sliding_layout但我不能設法得到所期望的行爲。 sliding_layout從不適合屏幕。

另一種我嘗試過的方法是將main_content替換爲一個空的ViewGroup,它必須match_paren(庫需要它),而main_content不在SlidingUpPanelLayout內部,但之前。

<android.support.v4.widget.DrawerLayout > 
    <com.hnhh.app3.fragments.model.FitsSystemWindowsFrameLayout> 

     <!-- NEW Main content - fragments placeholder --> 
     <com.hnhh.app3.fragments.model.FitsSystemWindowsFrameLayout /> 

     <com.sothree.slidinguppanel.SlidingUpPanelLayout> 
      <!-- Replaced old main_content with empty  --> 
      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"/> 

      <!-- Panel  --> 
      <FrameLayout /> 
     </com.sothree.slidinguppanel.SlidingUpPanelLayout> 

     <FrameLayout> 
      <com.hnhh.app3.widgets.BannerAdWrapper/> 
     </FrameLayout> 

    </com.hnhh.app3.fragments.model.FitsSystemWindowsFrameLayout> 

    <include layout="@layout/navigation" /> 

</android.support.v4.widget.DrawerLayout> 

與第二個解決方案的事情是,我有一個空的容器,將攔截所有觸摸事件,我更不知道如何將它們傳遞的主要內容。

有誰得到了解決方法嗎?由於

回答

0

好了,我發現通過一種方式。

我刪除了圖書館和使用自定義BottomSheetBehavior像https://github.com/fedorenkoalex/bottomsheetrecycler/。按照鏈接,看看它是如何實施的。感謝fedorenkoalex的解決方案。

結果幾乎相同,唯一的問題是當您滾動嵌套的回收站視圖(或其他滾動視圖)時,它將很好地處理滾動,除非無法再滾動:如果RecyclerView已經在頂部,您嘗試向上滾動,然後將底部表單向下推。最後這並不壞,因爲這是一種直觀的行爲。

0

您可以使用此XML佈局:

<!-- MAIN CONTENT --> 
<LinearLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:focusableInTouchMode="true" 
    android:orientation="vertical" 
    tools:context="com.amitupadhyay.clickin.in.amitupadhyay.clickin.ui.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" > 

     </android.support.v7.widget.Toolbar> 

     <android.support.design.widget.TabLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/tabLayout" 
      app:tabMode="scrollable" 
      app:tabGravity="fill" 
      app:tabTextAppearance="@style/MY_TAB_STYLE"> 
     </android.support.design.widget.TabLayout> 

    </android.support.design.widget.AppBarLayout> 

     <android.support.v4.view.ViewPager 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/viewPager"> 

     </android.support.v4.view.ViewPager> 

    <include layout="@layout/content_main" /> 

</LinearLayout> 


<!-- SLIDING LAYOUT --> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:clickable="true" 
    android:focusable="false" 
    android:id="@+id/dragView"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="68dp" 
     android:background="@color/colorPrimary" 
     android:id="@+id/bottomPannerLinearLayout" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/name" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:textSize="14sp" 
      android:textColor="@android:color/white" 
      android:gravity="center_vertical" 
      android:paddingLeft="10dp"/> 

     <Button 
      android:id="@+id/follow" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:textSize="14sp" 
      android:gravity="center_vertical|right" 
      android:paddingRight="10dp" 
      android:paddingLeft="10dp"/> 

    </LinearLayout> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/side_nav_bar" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/anyid" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center"/> 


      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="55dp" 
       android:id="@+id/anyotherid" 
       style="@style/AppTheme.Button" 
       android:layout_marginTop="20dp" 
       android:layout_gravity="center_horizontal" 
       android:textStyle="bold" 
       android:padding="10dp" 
       android:textSize="20sp" 
       android:text="Submit"/> 

     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 

這對我的偉大工程。 :)

+0

感謝您的回覆,我複製你的代碼裏面SlidingUpPanelLayout,但我仍然得到填充頂部的SlidingUpPanelLayout是狀態欄的高度。我試圖玩幾個變量,如* windowTranslucentStatus *,* windowActionBarOverlay *,* windowContentOverlay *,但仍然。我可能在某個地方錯了。 – bengous