2012-02-01 2 views
1

Я работаю над устройством для чтения электронных книг для Android. У меня есть мой контент, настроенный в прокручиваемом веб-просмотре. Для того, чтобы повернуть страницу, я хотел бы создать свой род страницу/эффект увлечения, как показано здесь: http://www.youtube.com/watch?v=sd5f4nauKTE#t=1m8sDrag "page" анимация

Я выставиться в onTouchListener моей WebView и добавил кэшированное изображение его в ImageView, и удалось перетащить его с пальцем, но у меня возникли проблемы с настройкой анимации на этом пути.

Вот мой код до сих пор:

<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);*/ 

    } 
} 

ответ

1

Нашли решение? В противном случае я бы сказал, вы можете установить фрагмент как представление и использовать FragmentManager и FragmentTransaction для размещения представления в Activity. Впоследствии вы можете добавить анимацию в транзакцию с помощью: setCustomAnimation (R.anim.New_in, R.anim.Old_out, R.anim.Old_in, R.anim.New_out);