您的位置:首页 > 移动开发 > Android开发

android 简单模仿IOS的3D Touch功能

2016-10-19 18:20 393 查看
        个人对IOS端3D Touch功能很感兴趣,想来自己实现,上网一搜,这类文章并不是很多,于是想自己实现一个。在自己绞尽脑汁的时候在github上搜索到一个开源项目可以实现简单3D Touch功能,在此坐一下笔记,以供后续参考。

话不多说,贴出核心代码:

//设置PeekView选项
PeekViewOptions options = new PeekViewOptions();
options.setBackgroundDim(1f);           // range: 0  - 1  (default is .6)   背景模糊度
options.setHapticFeedback(false);       // default is true

// it may be a good idea to set set these through resources so that you can use different options based on screen size and orientation
options.setWidthPercent(.4f);           // range: .1 - .9 (default is .6)
options.setHeightPercent(.4f);          // range: .1 - .9 (default is .5)

// you can also set the size of the PeekView using absolute values, instead of percentages.
// Setting these will override the corresponding percentage value.
// You should use this instead of setting the size of the view from the layout resources, as those get overridden.
options.setAbsoluteWidth(200);          // 200 DP
options.setAbsoluteHeight(200);         // 200 DP

// default is false. If you change this to true, it will ignore the width and height percentages you set.
options.setFullScreenPeek(true);
// default is true. Unless you are going to animate things yourself, i recommend leaving this as true.
//options.setFadeAnimation(false);
options.setUseFadeAnimation(true);

// PeekView has the ability to blur the background behind it, instead of just using a simple dark dim.
// If you set a blurred view, then it will invalidate whatever you set as your background dim.
// If you do this, please look at the installation steps for the blur effect, or the app will crash.
options.setBlurBackground(true);                            // default is true
// options.setBlurOverlayColor(Color.parse("#99000000"));      // #99000000 default
options.setBlurOverlayColor(Color.parseColor("#99000000"));    //背景颜色

//Peek.into(...).with(options).applyTo(...);

Peek.into(R.layout.image_peek, new SimpleOnPeek() {
@Override
public void onInflated(View rootView) {
WebView mWebView = (WebView) rootView.findViewById(R.id.mWebView);
final ProgressBar mProgressBar = (ProgressBar) rootView.findViewById(R.id.mProgressBar);
mWebView.loadUrl("http://www.baidu.com");
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
});

mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress==100) {
mProgressBar.setVisibility(View.GONE);

} else {
mProgressBar.setVisibility(View.VISIBLE);
}
mProgressBar.setProgress(newProgress);

super.onProgressChanged(view, newProgress);
}

});

}
}).with(options).applyTo(this, baseView);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android ios 3d 3DTouch