Java SlidengAppAnel中的ScrollView永远不会工作
我已经尽了一切努力让我的Java SlidengAppAnel中的ScrollView永远不会工作,java,android,xml,scrollview,Java,Android,Xml,Scrollview,我已经尽了一切努力让我的ScrollView和SlidingUppannelLayout能够运行Google地图应用程序处理它的方式。() 这是唯一一个似乎对人们有效的链接,但对我来说并不有效。 今天我已经跟随它4次了,每次我的ScrollView滚动,而我的slidengappannellayout完全不做任何事情。(它就在那里) 下面是我从GitHub上的SlideingUppannelLayout添加到代码中的代码 活动\u main.xml <com.bouy76.sportsm
ScrollView
和SlidingUppannelLayout
能够运行Google地图应用程序处理它的方式。()
这是唯一一个似乎对人们有效的链接,但对我来说并不有效。
今天我已经跟随它4次了,每次我的ScrollView
滚动,而我的slidengappannellayout
完全不做任何事情。(它就在那里)
下面是我从GitHub上的SlideingUppannelLayout
添加到代码中的代码
活动\u main.xml
<com.bouy76.sportsmantracker.SlidingUpPanelLayout
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:gravity="bottom"
app:panelHeight="68dp"
app:dragView="@+id/drag_view"
app:scrollView="@+id/scroll_view"> <!-- attrs.xml tag -->
<!-- MAIN CONTENT -->
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top">
<com.nutiteq.MapView
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<!-- SLIDING LAYOUT -->
<RelativeLayout
android:id="@+id/drag_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="false"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|start"
android:paddingLeft="@dimen/activity_vertical_margin"
android:text="Near Beaver Creek"
android:textSize="20sp" />
</LinearLayout>
<ScrollView
android:id="@+id/scroll_view" <!-- Match attrs reference -->
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:cacheColorHint="@android:color/white"
android:divider="@android:color/darker_gray"
android:dividerHeight="@dimen/divider_height"
android:layout_marginTop="68dp"
android:drawSelectorOnTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="5000dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:orientation="vertical"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</com.bouy76.sportsmantracker.SlidingUpPanelLayout>
android:layout\u width=“fill\u parent”
android:layout\u height=“fill\u parent”
android:background=“@android:color/transparent”
android:cacheColorHint=“@android:color/white”
android:divider=“@android:color/深灰色”
android:dividerHeight=“@dimen/divider\u height”
android:layout_marginTop=“68dp”
android:drawSelectorOnTop=“true”
slidengappanellayout.java
View mScrollView;
int mScrollViewResId = -1;
boolean isChildHandlingTouch = false;
float mPrevMotionX;
float mPrevMotionY;
...
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if (mDragViewResId != -1) {
setDragView(findViewById(mDragViewResId));
}
if (mScrollViewResId != -1) {
mScrollView = findViewById(mScrollViewResId);
}
}
...
private boolean isScrollViewUnder(int x, int y) {
if (mScrollView == null)
return false;
int[] viewLocation = new int[2];
mScrollView.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] + mScrollView.getWidth() &&
screenY >= viewLocation[1] &&
screenY < viewLocation[1] + mScrollView.getHeight();
}
...
//Removed the onInterceptTouchEvent Method
...
public boolean onTouchEvent(MotionEvent ev) {
if (!mCanSlide || !mIsSlidingEnabled) {
return super.onTouchEvent(ev);
}
mDragHelper.processTouchEvent(ev);
final int action = ev.getAction();
boolean wantTouchEvents = false;
switch (action & MotionEventCompat.ACTION_MASK) {
case MotionEvent.ACTION_UP: {
final float x = ev.getX();
final float y = ev.getY();
final float dx = x - mInitialMotionX;
final float dy = y - mInitialMotionY;
final int slop = mDragHelper.getTouchSlop();
View dragView = mDragView != null ? mDragView : mSlideableView;
if (dx * dx + dy * dy < slop * slop &&
isDragViewUnder((int) x, (int) y) &&
!isScrollViewUnder((int) x, (int) y)) {
dragView.playSoundEffect(SoundEffectConstants.CLICK);
if (!isExpanded() && !isAnchored()) {
expandPane(mAnchorPoint);
} else {
collapsePane();
}
break;
}
break;
}
}
return wantTouchEvents;
}
...
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (mScrollView == null)
return super.dispatchTouchEvent(ev);
final int action = MotionEventCompat.getActionMasked(ev);
final float x = ev.getX();
final float y = ev.getY();
if (action == MotionEvent.ACTION_DOWN) {
mDragHelper.shouldInterceptTouchEvent(ev);
mInitialMotionX = mPrevMotionX = x;
mInitialMotionY = mPrevMotionY = y;
isChildHandlingTouch = false;
} else if (action == MotionEvent.ACTION_MOVE) {
float dx = x - mPrevMotionX;
float dy = y - mPrevMotionY;
mPrevMotionX = x;
mPrevMotionY = y;
if (!isScrollViewUnder((int) x, (int) y))
return this.onTouchEvent(ev);
if (dy > 0) { // DOWN
// Is the child less than fully scrolled?
// Then let the child handle it.
if (mScrollView.getScrollY() > 0) {
isChildHandlingTouch = true;
return super.dispatchTouchEvent(ev);
}
if (isChildHandlingTouch) {
// Send an 'UP' event to the child.
MotionEvent up = MotionEvent.obtain(ev);
up.setAction(MotionEvent.ACTION_UP);
super.dispatchTouchEvent(up);
up.recycle();
ev.setAction(MotionEvent.ACTION_DOWN);
}
isChildHandlingTouch = false;
return this.onTouchEvent(ev);
} else if (dy < 0) {
if (mSlideOffset > 0.0f) {
isChildHandlingTouch = false;
return this.onTouchEvent(ev);
}
if (!isChildHandlingTouch) {
mDragHelper.cancel();
ev.setAction(MotionEvent.ACTION_DOWN);
}
isChildHandlingTouch = true;
return super.dispatchTouchEvent(ev);
}
} else if ((action == MotionEvent.ACTION_CANCEL) ||
(action == MotionEvent.ACTION_UP)) {
if (!isChildHandlingTouch) {
final float dx = x - mInitialMotionX;
final float dy = y - mInitialMotionY;
final int slop = mDragHelper.getTouchSlop();
if ((mIsUsingDragViewTouchEvents) &&
(dx * dx + dy * dy < slop * slop))
return super.dispatchTouchEvent(ev);
return this.onTouchEvent(ev);
}
}
return super.dispatchTouchEvent(ev);
}
View-mScrollView;
int mScrollViewResId=-1;
布尔值isChildHandlingTouch=false;
浮动mPrevMotionX;
浮动运动;
...
@凌驾
充气时受保护的空隙(){
超级充气();
如果(mDragViewResId!=-1){
setDragView(findViewById(mDragViewResId));
}
如果(mScrollViewResId!=-1){
mScrollView=findviewbyd(mscrollviewrid);
}
}
...
私有布尔IsCrollViewUnder(int x,int y){
如果(mScrollView==null)
返回false;
int[]viewLocation=新int[2];
mScrollView.getLocationOn屏幕(viewLocation);
int[]parentLocation=新int[2];
此.getLocationOn屏幕(父位置);
int screenX=parentLocation[0]+x;
int screenY=父位置[1]+y;
返回screenX>=视图位置[0]&&
screenX=视图位置[1]&&
screenY0){//DOWN
//孩子是否未完全滚动?
//那就让孩子来处理吧。
如果(mScrollView.getScrollY()>0){
isChildHandlingTouch=true;
返回超级dispatchTouchEvent(ev);
}
如果(isChildHandlingTouch){
//向孩子发送“向上”事件。
MotionEvent up=MotionEvent.Acquire(ev);
up.setAction(MotionEvent.ACTION\u up);
超级dispatchTouchEvent(up);
up.recycle();
ev.设置动作(MotionEvent.动作向下);
}
isChildHandlingTouch=false;
返回此.onTouchEvent(ev);
}else if(dy<0){
如果(mSlideOffset>0.0f){
isChildHandlingTouch=false;
返回此.onTouchEvent(ev);
}
如果(!isChildHandlingTouch){
mDragHelper.cancel();
ev.设置动作(MotionEvent.动作向下);
}
isChildHandlingTouch=true;
返回超级dispatchTouchEvent(ev);
}
}如果((action==MotionEvent.action_CANCEL)|
(action==MotionEvent.action\u UP)){
如果(!isChildHandlingTouch){
最终浮动dx=x-最小运动x;
最终浮点数dy=y-最小运动量;
final int slop=mdragheloper.gettouchlop();
如果((误用排水管)和
(dx*dx+dy*dy
再次检查我在哪里提取代码。
谢谢