2013-08-07 34 views
1

我使用這個庫,https://github.com/umano/AndroidSlidingUpPanel,我把一個listview裏面,但它不工作,沒有滾動,爲什麼? 不僅listview,整個佈局不滾動,也沒有textview,也沒有圖像,什麼都沒有。 這是我的xml代碼:SlidingUpPanel中的ListView是不可滾動的

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".Detalhe_linha" 

    <com.sothree.slidinguppanel.SlidingUpPanelLayout 
     android:id="@+id/sliding_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


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

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="Próximo onibûs sai do ponto final em" /> 

    <TextView 
     android:id="@+id/txtProx" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="X minutos" 
     android:layout_gravity="center" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <GridView 
     android:id="@+id/tabelaHorarios" 
     android:layout_width="315dp" 
     android:layout_height="match_parent" 
     android:layout_x="0dp" 
     android:layout_y="123dp" 
     android:layout_gravity="center" 
     android:numColumns="3" > 

    </GridView> 
</LinearLayout> 

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

       <TextView 
       android:layout_width="match_parent" 
       android:layout_height="34dp" 
       android:gravity="center|bottom" 
       android:text="Itinerário" 
       android:textSize="16sp" /> 

      <TextView 
       android:id="@+id/brought_by" 
       android:layout_width="match_parent" 
       android:layout_height="34dp" 
       android:gravity="center|top" 
       android:text="Arraste para cima" 
       android:textSize="14sp" 
       android:autoLink="web" /> 


       <TextView 
       android:id="@+id/itinerarios" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center|top" 
       android:text="" 
       android:textSize="17sp" 
       android:autoLink="web" /> 

     </LinearLayout> 
    </com.sothree.slidinguppanel.SlidingUpPanelLayout> 
</LinearLayout> 

順便說一句,抱歉我的英文不好。

回答

3

我發現問題是SlidingUpPanelLayout截獲了觸摸事件(onInterceptTouchEvent)。我的解決方案是重寫(或覆蓋)方法isDragViewHit,該方法在case MotionEvent.ACTION_DOWN中檢查並且可能潛在地取消對給定觸摸事件的攔截。

這是我的解決方案,取消攔截如果面板擴展允許點擊/滾動擴展子面板。這也意味着您無法滑動展開的面板。我通過單擊按鈕實現了面板的摺疊。檢查實施,它會給你想法什麼是可能的。

private boolean isDragViewHit(int x, int y) { 
    if(isExpanded()){ 
     //don't intercept touch if panel expanded 
     return false; 
    } 
    else{ 
     //original implementation - only allow dragging on mDragView 
     View v = mDragView != null ? mDragView : mSlideableView; 
     if (v == null) return false; 
     int[] viewLocation = new int[2]; 
     v.getLocationOnScreen(viewLocation); 
     int[] parentLocation = new int[2]; 
     this.getLocationOnScreen(parentLocation); 
     int screenX = parentLocation[0] + x; 
     int screenY = parentLocation[1] + y; 
     return screenX >= viewLocation[0] && screenX < viewLocation[0] + v.getWidth() && 
       screenY >= viewLocation[1] && screenY < viewLocation[1] + v.getHeight(); 
    } 
} 
+0

@ MSquare - 其實我在ListView中SlidingUpPanel。每個listview項目上都有一個按鈕。我想在按鈕上點擊關閉列表視圖項目來摺疊面板。我認爲setDragView()是摺疊面板的方法。但我不明白我如何在我的適配器類中實現?請告訴我,我該怎麼做。提前致謝。 – Lawrance

+0

@MSquare在哪裏添加此方法以及在哪裏調用它? –

+0

@iDroidExplorer,我檢查了AndroidSlidingUpPanel .java的github歷史記錄。方法是在2013年12月23日的提交中刪除了DragViewHit。 https://github.com/umano/AndroidSlidingUpPanel/commit/5986bd3cd947775ecce28878d3e7562287804bfa – MSquare

3

更好的方法是定義一個DragView。我使用textView,只有當我觸摸textView時它纔會滑動。所有其他視圖攔截點擊!

1

如果有人在這種情況下摔倒,我會在這裏離開我的方式。

Juliatzin指出,更簡潔的解決方案是使用方法setDragView(...)定義DragView,而不是重寫類方法。

要做到這一點,在你的國家,你的SlidingUpPanel菜單的佈局XML文件,你應該狀態的視圖,任何你想要的,一個ID,例如:

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

<LinearLayout ...> 
    MAIN CONTENT 
</LinearLayout> 

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#eee" 
     android:orientation="vertical" 
     android:clickable="true" 
     android:focusable="false"> 

    Views you want to be able to click on your menu... 

    <Button //This view will be the one that when touched on your SlidingUpPanel, said panel 
      //will close and let the other Views capture click events. You could give it some 
      //style so as to have it blend into the SlidingUpPanel if you don´t want it visible 
     android:id="@+id/close_SlidingUpPanel" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 

</LinearLayout>  

以及在您設置SlidingUpPanel活動你可以這樣做:

SlidingUpPanelLayout layout = (SlidingUpPanelLayout) findViewById(R.id.sliding_up_panel); 
layout.setDragView(findViewById(R.id.close_SlidingUpPanel)); 

希望很明顯,它可以幫助。默認情況下,我相信DragView設置爲null這意味着SlidingUpPanel的任何部分都可用於拖動,這就是爲什麼當您嘗試「點擊」其中一個子元素時它會關閉。