私はアンドロイドの電子ブックリーダーで作業しています。私は、スクロールできないウェブビューに自分のコンテンツを設定しました。ページをめくるために、私はここに示すようにページ/ドラッグ効果の種類を作成したいと思います:私は私のWebViewにonTouchListenerをsettedとImageViewのにキャッシュされた画像を追加しました http://www.youtube.com/watch?v=sd5f4nauKTE#t=1m8sドラッグ "ページ"アニメーション
、および私の指でそれをドラッグすることができましたが、途中でアニメーションを設定するのに問題があります。
ここに私のコードは、これまでのところです:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgContentBitmap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
/>
<ImageView
android:id="@+id/imgNext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
/>
<ImageView
android:id="@+id/imgPrev"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
/>
<android.webkit.WebView
android:id="@+id/webPageContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</android.webkit.WebView>
</FrameLayout>
と活動:
public class TestPageActivity extends Activity {
/** Called when the activity is first created. */
private WebView webView;
private Bitmap bitmap;
private ImageView contentBitmap;
private FrameLayout.LayoutParams params;
private int pressedX;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
params = new FrameLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
params.leftMargin = 0;
params.topMargin = 0;
webView = (WebView) findViewById(R.id.webPageContent);
webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);
((FrameLayout)(webView.getParent())).setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event){
int eventAction = event.getAction();
int currentX = (int) event.getX();
Log.d("main", "current x = "+currentX);
Log.d("main", "pressed x = "+pressedX);
switch(eventAction){
case MotionEvent.ACTION_DOWN:
Log.d("main", "down");
pressedX = (int) event.getX();
break;
case MotionEvent.ACTION_MOVE:
Log.d("main", "move");
params.leftMargin = (pressedX-currentX);
contentBitmap.setLayoutParams(params);
break;
case MotionEvent.ACTION_UP:
Log.d("main", "up");
break;
}
return true;
}
});
webView.loadData(getString(R.string.lorem_ipsum), "text/html", "utf-8");
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
}
});
webView.setPictureListener(new PictureListener() {
@Override
public void onNewPicture(WebView view, Picture picture){
webView.setDrawingCacheEnabled(true);
webView.layout(0, 0, webView.getWidth(), webView.getBottom());
webView.buildDrawingCache(true);
bitmap = Bitmap.createBitmap(webView.getDrawingCache());
webView.setVisibility(WebView.INVISIBLE);
webView.setDrawingCacheEnabled(false);
contentBitmap.setImageBitmap(bitmap);
webView.setPictureListener(null);
}
});
contentBitmap = (ImageView) findViewById(R.id.imgContentBitmap);
/*
contentBitmap.setImageBitmap(bitmap);*/
}
}