2013-08-07 29 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的任何部分都可用于拖动,这就是为什么当您尝试“点击”其中一个子元素时它会关闭。