转载:
http://fmck.blog.163.com/blog/static/9579205720114494636176/
访问本地磁盘和SD卡上的HTML,前部分content://com.android.htmlfileprovider是Provider的标准,后面是程序目录。
比如sdcard的tesl.html
直接在浏览器里输入content://com.android.htmlfileprovider/sdcard/test.html回车就可以看到网页了。
方法二:
webView.loadUrl( "file://" + filename);
二,重写了view的touchevent后:
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
scaleAnimationHelper.ScaleInAnimation(HomeRelativeLayout.this);
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
int[] location = new int[2];
HomeRelativeLayout.this.getLocationOnScreen(location);
if (inRangeOfView(HomeRelativeLayout.this, event)
&& mOnViewClick != null) {
Log.e("water", "is range");
mOnViewClick.onClick(HomeRelativeLayout.this.getId());
}
scaleAnimationHelper.ScaleOutAnimation(HomeRelativeLayout.this);
break;
}
return true;
}
private boolean inRangeOfView(View view, MotionEvent ev) {
float X = ev.getRawX();
float Y = ev.getRawY();
int[] location = new int[2];
view.getLocationOnScreen(location);
int view_fromx = location[0];
int view_tox = location[0] + view.getWidth();
int view_fromy = location[1];
int view_toy = location[1] + view.getHeight();
if (X < view_fromx || X > (view_tox) || Y < view_fromy
|| Y > (view_toy)) {
return false;
}
return true;
}
需要用
inRangeOfView
方法判断手指收起时的位置是否在改view里面
其中:
float X = ev.getRawX();//获取手指在屏幕上的x位置
float Y = ev.getRawY();
int[] location = new int[2];
view.getLocationOnScreen(location);//获取屏幕view在屏幕上的位置
getX()是表示Widget相对于自身左上角的x坐标,而getRawX()是表示相对于屏幕左上角的x坐标值(注意:这个屏幕左上角是手机屏幕左上角,不管activity是否有titleBar或是否全屏幕),getY(),getRawY()一样的道理
转自:http://www.cnblogs.com/foura/articles/2016881.html