gpt4 book ai didi

android - Ice Cream Sandwich 浏览行为

转载 作者:太空狗 更新时间:2023-10-29 15:19:54 28 4
gpt4 key购买 nike

我有一个针对 SDK 3.0 构建的应用程序。

在这个应用程序中有一个相对布局,它有一个全屏 VideoView,其下方有一个按钮。视频 View 上设置了一个 onTouchListener,用于监听手势。

视频播放完毕后,VideoView 设置为 visibility(View.GONE) 在运行 Honeycomb(Toshiba Thrive 和 HTC Flyer)的设备上,此功能符合我的预期它到。一旦 VideoViewGONE 按钮就可以点击了。

但是在运行 ICS (Motorola Xoom) 的设备上,当我尝试按下按钮时,事件会转到 VideoView 触摸监听器,而不是按钮点击监听器。

View 在这种情况下的行为方式是在 ICS 上有意改变的还是这是一个错误?

此外,我尝试解决这个问题的第一件事也给了我一些奇怪的结果。

我添加了这些行而不是 setVisibility(View.GONE);

    Log.i(MainActivity.myTag, "vid is null ? " + (mVideoView == null));
Log.i(MainActivity.myTag, "lyt is null ? " + (vidLyt == null));
vidLyt.removeView(mVideoView); //This line throws null pointer

认为如果 VideoView 从我的父布局中移除,它肯定不再接受触摸事件。

但这会在 removeView() 调用上导致一个空指针。即使上面的日志语句表明这两个对象实际上都不为空。这是异常(exception)情况:

据我所知,它实际上并没有指向我的 Activity 中的任何一行,但这 3 个语句是此时唯一被调用的 3 个语句,并且两个日志语句都成功完成。

01-20 16:32:42.480: ERROR/AndroidRuntime(9416): java.lang.NullPointerException
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2488)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.view.View.getDisplayList(View.java:10415)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2597)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.view.View.getDisplayList(View.java:10380)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2597)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.view.View.getDisplayList(View.java:10380)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2597)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.view.View.getDisplayList(View.java:10380)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:840)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.view.ViewRootImpl.draw(ViewRootImpl.java:1910)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1634)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.os.Looper.loop(Looper.java:137)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at java.lang.reflect.Method.invoke(Method.java:511)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-20 16:32:42.480: ERROR/AndroidRuntime(9416): at dalvik.system.NativeStart.main(Native Method)

编辑:这里是相关部分。

        mVideoView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent me){
if(me.getAction() == MotionEvent.ACTION_DOWN){
touchY = me.getY();
//I am using the if statement below to fix the unexpected behavior currently.
//by returning false even though the VideoView receives the touch, this
//causes it to essentiall ignore it and pass it along to the button.
if(mVideoView.getVisibility() == View.GONE){
return false;
}
}else if(me.getAction() == MotionEvent.ACTION_UP){
Log.i(MainActivity.myTag, "Old = " + touchY + " New = " + me.getY());
//Moved north a little is the gesture I am interested in.
if(me.getY() < (touchY - 100)){


Thread t = new Thread() {
public void run(){
timeStamp = mVideoView.getCurrentPosition();
mVideoView.stopPlayback();

//Since we are in back thread use a handler to GONEify the VideoView
animVidHandler.sendEmptyMessage(0);

//There is some network stuff here that justifies the use of a
//different thread. But I am certain it isn't affecting the
//behavior of my views.

}
};
t.start();
}
}
return true;
}
});

处理程序回调内部只有 1 个语句:

mVideoView.startAnimation(flyOffAnim); //translate animation to "fly off" the screen.

之前忘了说动画了。这可能与这种行为有关吗?

flyOffAnimation 设置了一个仅包含 1 个语句的 completionListener:

mVideoView.setVisibility(View.GONE);

最佳答案

Was the way that Views are intended to behave in this situation changed purposely on ICS or is this a bug?

VideoView 实际上是一个 SurfaceView,它实际上不是一个普通的 View,尽管它可以在电视上播放。

As far as I can tell it doesn't actually point to any line in my activity, but these 3 statements are the only 3 getting called at this time and both Log statments complete successfully.

您不会从这三个语句中得到 NullPointerException。您可能会在其他地方收到 NullPointerException 作为这三个语句的副作用。在这种情况下,我不知道你为什么会这样做。

或许尝试切换到让两者成为 ViewFlipper 中的对等体并以这种方式在模式之间切换。

关于android - Ice Cream Sandwich 浏览行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8948772/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com