簡體   English   中英

在Android中,當滑動更改屏幕時如何用兩個屏幕顯示動畫

[英]In Android, when swipe to change the screen how to show an animation with both screen

對不起,標題不夠明確。 我不知道如何表達它,但這里的圖像說明了一切。

在谷歌閱讀器應用程序中,如果使用在當前帖子上向左或向右滑動,他們將看到第一個帖子在第二個帖子移動時移出。這是一個很好的效果,但我不知道如何實現它。

有任何想法嗎?

在此輸入圖像描述

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#a4c639"
android:orientation="vertical" >

<android.support.v4.view.ViewPager
    android:id="@+id/awesomepager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>





 public class ReadRawActivity extends Activity {

    private ViewPager awesomePager;
    private static int NUM_AWESOME_VIEWS = 3;
    private static Context cxt;
    private AwesomePagerAdapter awesomeAdapter;

    /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    cxt = ReadRawActivity.this;

    awesomeAdapter = new AwesomePagerAdapter();
    awesomePager = (ViewPager) findViewById(R.id.awesomepager);
    awesomePager.setAdapter(awesomeAdapter);
}

private class AwesomePagerAdapter extends PagerAdapter{




            @Override
            public int getCount() {
                    return NUM_AWESOME_VIEWS;
            }

        /**
         * Create the page for the given position.  The adapter is responsible
         * for adding the view to the container given here, although it only
         * must ensure this is done by the time it returns from
         * {@link #finishUpdate()}.
         *
         * @param container The containing View in which the page will be shown.
         * @param position The page position to be instantiated.
         * @return Returns an Object representing the new page.  This does not
         * need to be a View, but can be some other container of the page.
         */
            @Override
            public Object instantiateItem(View collection, int position) {
                    TextView tv = new TextView(cxt);
                    tv.setText("View Pager" + position);
                    tv.setTextColor(Color.WHITE);
                    tv.setTextSize(30);

                    ((ViewPager) collection).addView(tv,0);

                    return tv;
            }

        /**
         * Remove a page for the given position.  The adapter is responsible
         * for removing the view from its container, although it only must ensure
         * this is done by the time it returns from {@link #finishUpdate()}.
         *
         * @param container The containing View from which the page will be removed.
         * @param position The page position to be removed.
         * @param object The same object that was returned by
         * {@link #instantiateItem(View, int)}.
         */
            @Override
            public void destroyItem(View collection, int position, Object view) {
                    ((ViewPager) collection).removeView((TextView) view);
            }



            @Override
            public boolean isViewFromObject(View view, Object object) {
                    return view==((TextView)object);
            }


        /**
         * Called when the a change in the shown pages has been completed.  At this
         * point you must ensure that all of the pages have actually been added or
         * removed from the container as appropriate.
         * @param container The containing View which is displaying this adapter's
         * page views.
         */
            @Override
            public void finishUpdate(View arg0) {}


            @Override
            public void restoreState(Parcelable arg0, ClassLoader arg1) {}

            @Override
            public Parcelable saveState() {
                    return null;
            }

            @Override
            public void startUpdate(View arg0) {}

}


}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM