2016-05-30 17 views
6

Mam układ z ScrollView, który ma ListView w środku. Wszystko działa dobrze, ale jeśli otworzę DrawerLayout, ScrollView będzie przewijany trochę. Wystarczy spojrzeć na te zrzuty ekranu.ListView wewnątrz ScrollView z DrawerLayout

enter image description here

Oto otwieram DrawerLayout

enter image description here

Potem zamknąć DrawerLayout. enter image description here

Jak widać, przewijany jest trochę. Jak to naprawić? To mój xml:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/menuLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 

    <RelativeLayout 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <ProgressBar 
      android:id="@+id/progressWheelBar" 
      style="?android:attr/progressBarStyleLarge" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" /> 

     <TextView 
      android:id="@+id/noDataTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:text="@string/noData" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:visibility="gone" /> 

     <LinearLayout 
      android:id="@+id/actionBarLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/transparent" 
      android:orientation="vertical" > 

      <RelativeLayout 
       android:id="@+id/innerActionBarLayout" 
       android:layout_width="match_parent" 
       android:layout_height="55dp" 
       android:background="@color/material_blue_500" > 

       <ImageButton 
        android:id="@+id/menuButton" 
        android:layout_width="36dp" 
        android:layout_height="36dp" 
        android:layout_alignParentLeft="true" 
        android:layout_centerVertical="true" 
        android:layout_marginLeft="5dp" 
        android:background="@null" 
        android:src="@drawable/ic_menu_white_24dp" /> 

       <TextView 
        android:id="@+id/title" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerVertical="true" 
        android:layout_marginLeft="16dp" 
        android:layout_toRightOf="@+id/menuButton" 
        android:textColor="@color/white" 

        android:textSize="18sp" /> 
      </RelativeLayout> 
     </LinearLayout> 

     <ScrollView 
      android:id="@+id/mainScrollView" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_below="@+id/actionBarLayout" 
      android:fillViewport="true" 
      android:scrollbars="none" 
      > 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" > 
       <!-- Here goes the frame layout with a listview inside --> 
       <FrameLayout 
        android:id="@+id/container" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:visibility="gone" 
        tools:context="ru.tenet.ttk.MainActivity" /> 
      </LinearLayout> 
     </ScrollView> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="2dp" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/actionBarLayout" 
      android:background="@drawable/shadow_down" /> 

    </RelativeLayout> 

    <LinearLayout 
     android:layout_width="250dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="left|start" 
     android:background="@color/white" 
     android:orientation="vertical" 
     android:clickable="true" > 

     <ListView 
      android:id="@+id/menuListView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:listSelector="@drawable/list_selector" 
      android:layout_marginTop="15dp" 
      android:divider="@null" /> 
    </LinearLayout> 

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

Czy naprawdę potrzebujesz "ScrollView"? Lista 'ListView' przewija się samodzielnie. –

+0

Możesz użyć 'NestedScrollView' –

+0

Możesz umieścić ListView wewnątrz widoku przewijania, ale musisz obsłużyć zarówno przewijanie, widok listy Bec ma własną funkcję przewijania, a widok przewijania ma funkcję przewijania do, gdy spróbujesz przewinąć sprzeczne, więc musisz obsługiwać zdarzenia przewijania nadrzędnego i podrzędnego. –

Odpowiedz

0

Trudno dać jednoznacznej odpowiedzi, ponieważ nie pisał swój kod. Jednym z powodów może być ustawienie stylu "windowActionBarOverlay = true" w Twojej aktywności. Z powodu tego ustawienia treść działania rozpoczyna się na samym początku strony i znajduje się poza paskiem akcji.

Poza tym, jak stwierdzili komentatorzy powyżej, czy rzeczywiście potrzebujesz ListView wewnątrz ScrollView? ListView sam jest ScrollView.

Najlepsze, jeśli opublikujesz kod swojej działalności Szuflady i aktywności związanej z zawartością.

0

Proste rozwiązanie wykorzystuje metodę headerView - ListView.addHeaderView(); Myślę, że nie trzeba używać Scrollview & wystarczy dodać pojemnik jako headerView

0

Najprościej byłoby użyć RecyclerView i zdefiniować headerRow pokazać swój tytuł.

0

Przypisanie szufladyListener do modułu DrawerLayout iw zdarzeniu onDrawerClosed przewinięcie scrollView do góry.

mDrawer.setDrawerListener(new DrawerListener() { 
     @Override 
     public void onDrawerSlide(View view, float v) { 

     } 

     @Override 
     public void onDrawerOpened(View view) { 

     } 

     @Override 
     public void onDrawerClosed(View view) { 
      mScrollView.fullScroll(ScrollView.FOCUS_UP); 
     } 

     @Override 
     public void onDrawerStateChanged(int i) { 

     } 
    }); 
Powiązane problemy