0

讓我介紹你到我的活動:Android的滾動型不活動與抽屜佈局滾動

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

    <include 
     android:id="@+id/toolbar_actionbar" 
     layout="@layout/toolbar_default" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

    <FrameLayout 
     android:id="@+id/main_fragment_container" 
     android:layout_width="match_parent" 
     android:layout_below="@+id/toolbar_actionbar" 
     android:layout_height="match_parent"/> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/toolbar_actionbar"> 

     <FrameLayout 
      android:id="@+id/container" 
      android:layout_width="match_parent" 
      android:clickable="true" 
      android:layout_height="match_parent"/> 

     <!-- android:layout_marginTop="?android:attr/actionBarSize"--> 
     <fragment 
      android:id="@+id/fragment_drawer" 
      android:name="com.package.name.navigationdrawer.NavigationDrawerFragment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      app:layout="@layout/fragment_navigation_drawer"/> 
    </android.support.v4.widget.DrawerLayout> 
</RelativeLayout> 

的FrameLayout main_fragment_container是我加載取決於抽屜式導航欄選擇不同的片段,但是當我打開一個片段與ScrollView滾動不起作用,當加載片段時,我可以看到滾動條,表明此時只有一小部分在屏幕上,但它永遠不會滾動。我嘗試了一些提到在LinearLayout中包含ScrollView的建議,但沒有任何區別。

我懷疑導航抽屜「截獲」應該到達ScrollView的事件,但我失去了做什麼。這是片段:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical"> 

    <ScrollView 
     android:id="@+id/fragment_who_scrollview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="vertical" 
     android:fillViewport="true"> 

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

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:adjustViewBounds="true" 
       android:src="@drawable/header_pic_s"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" 
       android:text="TEEEEEST" 
       android:gravity="center" 
       android:padding="20dp"/> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

感謝您的時間。

UPDATE - 讓我添加一些額外的信息:

  • 這裏的問題不是滾動型本身,而是事實,在我的活動佈局DrawerLayout是「上面」的滾動型防止任何觸摸事件到達ScrollView。如果我刪除DrawerLayout,ScrollView會滾動JUST FINE。

  • 同樣,如果我在活動佈局中將DrawerLayout後面的ScrollView放置在ScrollView中,但當然DrawerLayout不能按預期工作,因爲它必須位於其他任何位置之上。

我希望適當解釋自己,通過測試我敢肯定的是什麼問題,但我不知道如何解決它,我的抽屜式導航的經驗是有限的,我不知道如何讓滾動事件傳遞給ScrollView,而不是讓DrawerLayout攔截它。佈局的

+0

這並不解決您的問題,但你不需要你的滾動視圖的父linearlayout。您的滾動視圖應該充當主視圖。 –

+0

謝謝,這是完全沒有必要的,我只是刪除它。我只嘗試過,因爲它在ScrollViews滾動問題時作爲答案給出。 – dbar

+0

沒有問題:)爲什麼你的framelayout(容器)是可點擊的?這是你添加內容的地方嗎?嘗試刪除此標誌。 –

回答

1

你應該將ID爲 「main_fragment_container」 中的FrameLayout裏面drawerlayout這樣的:

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

<include 
    android:id="@+id/toolbar_actionbar" 
    layout="@layout/toolbar_default" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 


<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/toolbar_actionbar"> 

    <FrameLayout 
     android:id="@+id/main_fragment_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/toolbar_actionbar" /> 

    <!-- android:layout_marginTop="?android:attr/actionBarSize"--> 
    <fragment 
     android:id="@+id/navigation_drawer" 
     android:name="vodafone.navdrawertest.NavigationDrawerFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:layout="@layout/fragment_navigation_drawer" /> 
</android.support.v4.widget.DrawerLayout> 

+1

我會給這個正確的答案。我也用這個解決方案回答了我的問題(哪個工作正常)。謝謝! (特別是托馬斯幫我自己達到這個解決方案) – dbar

+0

我用過這個,但我仍然無法向下滾動我的抽屜。 DrawerLayout之前需要有一個RelativeLayout嗎? –

0

嘗試重新排序:

<android.support.v4.widget.DrawerLayout 
android:id="@+id/drawer" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

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

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

     <include 
      android:id="@+id/toolbar_actionbar" 
      layout="@layout/toolbar_default" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

     <FrameLayout 
      android:id="@+id/main_fragment_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 

    </LinearLayout> 

    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</FrameLayout> 

<!-- android:layout_marginTop="?android:attr/actionBarSize"--> 
<fragment 
    android:id="@+id/fragment_drawer" 
    android:name="com.ulusol.knowmyshop.navigationdrawer.NavigationDrawerFragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    app:layout="@layout/fragment_navigation_drawer"/> 

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

謝謝,但這種佈局擾亂了一切結構明智,並給我沒有滾動和沒有導航抽屜。 – dbar

+0

儘管我無法將此作爲正確的解決方案,但這有助於我修復佈局。我的FrameLayout確實必須進入DrawerLayout才能滾動。 – dbar

+0

我重新排列了它。但我不知道'容器'是如何實現的。最後,它幫助找到你正確的答案:) –

0

感謝Thomas指導我答案。

ScrollView去的FrameLayout必須在DrawerLayout 內部滾動。我還放棄了其他容器佈局,因爲它沒有被使用。這是活動仍然是如何:

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

    <include 
     android:id="@+id/toolbar_actionbar" 
     layout="@layout/toolbar_default" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/toolbar_actionbar"> 

     <FrameLayout 
      android:id="@+id/main_fragment_container" 
      android:layout_width="match_parent" 
      android:layout_below="@+id/toolbar_actionbar" 
      android:layout_height="match_parent"/> 

     <!-- android:layout_marginTop="?android:attr/actionBarSize"--> 
     <fragment 
      android:id="@+id/fragment_drawer" 
      android:name="com.package.name.navigationdrawer.NavigationDrawerFragment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      app:layout="@layout/fragment_navigation_drawer"/> 
    </android.support.v4.widget.DrawerLayout> 
</RelativeLayout>