2013-09-26 94 views
1

首先,我想爲我的英語apollogize,我來自俄羅斯,我希望谷歌translater幫助我描述我的問題=)。 所以問題是 - 我有一個GridView和ExpandableListView裏面的ScrollView,我知道我不應該把一個滾動視圖內滾動視圖,但爲我的目標,我找不到替代。在我的項目中,我有一個類別的商業目錄(如「電子」,「主頁&花園」,「電機」等),我想要做的就是將最流行的類別放入gridView中(併爲它們添加圖標)和使滾動視圖滾動它像單一佈局。但我的scrollView不會滾動它,我怎麼能做到這一點?ScrollView中的ListView和GridView。 ScrollView不會滾動

我bizCatalog Actvivty:

enter image description here

我bizCatalog佈局:

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

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

    <ProgressBar 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Загрузка списка..." /> 
</LinearLayout> 

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

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

     <GridView 
      android:id="@+id/bizFavoritesGrid" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:columnWidth="90dp" 
      android:gravity="center" 
      android:horizontalSpacing="10dp" 
      android:numColumns="auto_fit" 
      android:paddingTop="10dp" 
      android:stretchMode="columnWidth" 
      android:verticalSpacing="10dp" > 
     </GridView> 

     <ExpandableListView 
      android:id="@+id/bizList" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:cacheColorHint="#00000000" > 
     </ExpandableListView> 
    </LinearLayout> 
</ScrollView> 

</ViewSwitcher> 

回答

1

您可以通過覆蓋滾動視圖的dispatchTouchEvent(MotionEvent event)函數來實現上述目的。在這個函數裏面發送事件給你的孩子listview。那麼你也需要覆蓋dispatchTouchEvent像你這樣的列表視圖

int[] location = new int[2]; 
    listView.getLocationOnScreen(location); 

    if (e.getRawX() > location[0] && e.getRawX()< location[0] + listView.getWidth() && 
    e.getRawY() > location[1] && e.getRawY() < location[1] + listView.getHeight()) 
    { 
    int[] checkListLoc = new int[2]; 

    listView.getLocationOnScreen(checkListLoc); 
    var offset = checkListLoc[1] - (e.getRawY() - e.GetY()); 
    e.OffsetLocation(0, 0 - offset); 

    listView.dispatchTouchEvent(e); 
    return true; 
} 
return base.dispatchTouchEvent(e); 
+0

如果你想在滾動視圖中顯示適配器視圖,你必須處理地獄。我以爲你沒有任何其他選擇 –

0

根據Android準則,您不能將一個可滾動佈局用於另一個。如果您使用的是ScrollView,那麼您不能在其中使用ListView。因爲這兩種佈局都是可滾動的。所以請使用任何一個滾動你的。

0

先刪除滾動視圖。使用listview並添加gridview作爲listview的footerview。它會很好。絕對解決你的問題。

+0

好吧,我會嘗試它(我知道我可以添加gridview到列表視圖標題) – whizzzkey