Я использую эту библиотеку, https://github.com/umano/AndroidSlidingUpPanel, и я помещаю listview внутрь, но это не работает, без прокрутки, почему? Не только listview, весь макет не катится, ни textview, ни изображение, ничего. Вот мой xml-код:
<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>
Кстати, извините за мой плохой английский.
Я обнаружил, что проблема в том, что 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();
}
}
лучший способ - определить DragView. Я использую textView, и он скользит только тогда, когда я касаюсь textView. Все остальные виды перехватывают клики!
Я оставляю свой способ сделать это здесь, если кто-то еще наткнется на эту ситуацию.
Более чистое решение, как утверждает Юлиатин, заключается в определении DragView с помощью метода setDragView(...)
а не в переопределении метода классов.
Для этого в вашем XML файле, где вы указываете макет вашего меню SlidingUpPanel, вы должны указать вид, независимо от того, что вы хотите, с идентификатором, например:
<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 делает его доступным для перетаскивания, и поэтому он закрывается, когда вы пытаетесь "щелкнуть" по одному из его дочерних элементов.