小编Dav*_*ave的帖子

Android初学者:了解MotionEvent动作

我无法让我的活动生成MotionEvent.ACTION_UP.可能是初学者的错误.

在LogCat中,我只看到ACTION_MOVE事件(int值为3).我也看到了X/Y坐标.没有ACTION_DOWN,也没有ACTION_UP.

我到处寻找解决方案.我发现,这似乎是同我的问题的一个论坛一个问题,但没有解决方案提出: http://groups.google.com/group/android-developers/browse_thread/thread/9a9c23e40f02c134/bf12b89561f204ad?lnk=gst&q = ACTION_UP#bf12b89561f204ad

这是我的代码:

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.webkit.WebView;

public class Brand extends Activity {

public WebView webview;
public float currentXPosition;
public float currentYPosition;

@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

    webview = new WebView(this);
    setContentView(webview);
    webview.loadUrl("file:///android_asset/Brand.html");


 }

@Override
public boolean onTouchEvent(MotionEvent me) {

    int action = me.getAction();
    currentXPosition = me.getX();
    currentYPosition = me.getY();

    Log.v("MotionEvent", "Action = " + action);
    Log.v("MotionEvent", "X = " + currentXPosition + "Y = " + currentYPosition); …
Run Code Online (Sandbox Code Playgroud)

android

13
推荐指数
2
解决办法
4万
查看次数

Android:获取WebView的滚动位置

我是Android新手。

我只想知道用户在页面上的滚动位置。当网页上的某个点出现在屏幕底部时,我想触发一个事件。但是此代码会导致异常。我知道WebView从View继承了getScrollY()。我执行不正确吗?

提前致谢。

public class Scroll extends Activity {

    public WebView webview;
    public float yPos;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        WebView webview = new WebView(this);
        setContentView(webview);
        webview.loadUrl("file:///android_asset/Scroll.html");
    }


    public boolean onTouchEvent(final MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_MOVE) {
            yPos = webview.getScrollY();
            Log.v("Scroll", "yPos = " + yPos); 
        }
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

android webview

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×2

webview ×1