在onuch之后,它不能在Android上进行播放

前端之家收集整理的这篇文章主要介绍了在onuch之后,它不能在Android上进行播放前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
(我删除了所有的代码,因为下面的代码也不工作.)

附加信息和简短摘要 – 真正的问题

这很有趣.我有另一个项目是一个简单的活动.在那里,我可以拖现在在这个项目中,我阻止了所有地方的评论.只有几条线,像另一个项目,但仍然没有拖累.

Drag is in progress,but there is no drag window handle.

有时它说.我也搜索过,但我不能这样做.

代码现在是:

protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG,"matching ggame OnCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_matchgame);
    setupForGame();
    Log.d(TAG,"matching game OnCreate ends");
}//oncreate end

void setupForGame(){
    Log.d(TAG,"matching game setupforgame");

    imageAnswer = (ImageView) findViewById(R.id.imgAnswer);

    imageAnswer = (ImageView) findViewById(R.id.imgAnswer);
}

public boolean onTouch(View view,MotionEvent motionEvent) {
    Log.d(TAG,"ontouch never");
    if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
        ClipData data = ClipData.newPlainText("","");
        View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
        view.startDrag(data,shadowBuilder,view,0);
        view.setVisibility(View.INVISIBLE);
        return true;
    }
    else {
        return false;
    }
}

@Override
public boolean onDrag(View receivingLayoutView,DragEvent dragEvent) {
    Log.d(TAG,"ondrag start");

还没到里面

我做了静态,看看是否是这个问题.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:id="@+id/relative_layout"
    tools:context=".games.MatchingGame">

    <ImageView
        android:id="@+id/imgAnswer"
        android:layout_width="111dp"
        android:layout_height="111dp"
        android:src="@drawable/b3_1"
        android:layout_alignParentLeft="true"
        android:layout_centerInParent="true"
        />

</RelativeLayout>

它与另一个项目相同,但它不工作.我看着所有的可能性和调试.

请不要问拖动方法代码;这不重要.它不能输入.

当我按住并拖动图像时,这将进入一个循环,直到我离开:

I/SPRDHWComposer: util[1759] warning: osdLayer width 111,stride 112,not equal!

当我离开图像时:

V/WindowManager: rotationForOrientationLw(orient=0,last=1); user=0 USER_ROTATION_LOCKED sensorRot
V/WindowOrientationListener: getProposedRotation : mEnabled = false,mUsedautorotioansensor =true
 W/WindowManager: Drag is in progress but there is no drag window handle.

如果触摸有问题,我也做出了这一点,但是它仍然是一样的:

imageAnswer.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v,MotionEvent event) {
        //if (event.getAction() == MotionEvent.ACTION_DOWN) { Log.d(TAG,"ontouch down");

        //Log.d(TAG,"parent "+ String.valueOf(img1.getParent()));
        Log.d(TAG,"view "+String.valueOf(v));

        ClipData data = ClipData.newPlainText("","");
        View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
        v.startDrag(data,v,0);
        v.setVisibility(View.INVISIBLE);
        return true;

这是我的拖放工作的旧项目.我看不到区别:

https://gist.github.com/anonymous/540a70e05de6d765e20896b47deb7eb2

当我这样做

imageAnswer.setOnDragListener(new View.OnDragListener() {
    public boolean onDrag(View v,DragEvent event) {  Log.d(TAG,"drag");

        return false;
    }
});

它也不工作.没有日志.

这也不是一个日志:

imageAnswer.setOnDragListener(new dropListener());

private class dropListener implements View.OnDragListener {

    @Override
    public boolean onDrag(View v,DragEvent event) {Log.d("Chic","ondrag");
        switch (event.getAction()) {

            case DragEvent.ACTION_DRAG_STARTED:
                break;

            case DragEvent.ACTION_DRAG_ENTERED:
                break;

            case DragEvent.ACTION_DRAG_EXITED:
                break;

            case DragEvent.ACTION_DROP:
                break;

            case DragEvent.ACTION_DRAG_ENDED:
                break;

            default:
                break;
        }
        return true;
    }
 }

两个项目有区别:

这可能是原因吗?

我也试图把所有setondrag setontouch放在内部.

解决方法

就我所见(例如,here)而言,onTouch和onDrag根本不起作用.为什么不把所有的代码放在onDrag中?根据你的代码,这应该是足够的.

猜你在找的Android相关文章