自定义动画

时间:2016-03-08 10:08:44

标签: android animation sliding

如何在android中实现具有滑动效果和颜色过渡的此类动画。 (IOS喜欢滑动控制器)。 提前谢谢。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

试试我的示例代码

activity_main_activity2

 {
"result": {
    "data": {
        "provider": "facebook",
        "pages": {
            "pagination": {
                "current_page": 1,
                "total_pages": 1,
                "entries_per_page": 250,
                "total_entries": 2,
                "order": {
                    "field": "date_creation",
                    "direction": "desc"
                }
            },
            "count": 2,
            "entries": [
                {
                    "user_token": "48d6b4a9-afd7-4ee7-b359-45bbf618ebe9",
                    "identity_token": "f5148587-3925-4fec-a214-3a339a023d2b",
                    "page_token": "c66c2d03-c9de-485b-9aea-445c405d44ab",
                    "date_creation": "Tue, 07 Apr 2015 10:37:52  0200",
                    "name": "Test Page",
                    "description": "This is the description of the page.",
                    "category": "Community",
                    "num_likes": 27,
                    "link": "https://www.facebook.com/test-page",
                    "thumbnailUrl": "https://graph.facebook.com/1234567890/picture?type=square",
                    "pictureUrl": "https://graph.facebook.com/1234567890/picture?type=large",
                    "source": {
                        "identifier": 1234567890,
                        "access_token": {
                            "key": "E797C0013811A1D1E35AD7EDD10FB99986DB664B0996C76ED9AE5E0A5151BBF9E797C0013811A1D1E35AD7EDD10FB99986DB664B0996C76ED9AE5E0A5151BBF9"
                        }
                    }
                },
                {
                    "user_token": "1f178827-c746-43e0-84d0-75cfd0513b1e",
                    "identity_token": "462fae22-f46b-4343-838c-1fc35113e92c",
                    "page_token": "886a4c73-fa1a-4261-839f-42672f42b842",
                    "date_creation": "Tue, 07 Apr 2015 10:37:52  0200",
                    "name": "Another Test Page",
                    "description": "This is the description of the page.",
                    "category": "Computers/internet website",
                    "num_likes": 2119,
                    "link": "https://www.facebook.com/another-test-page",
                    "thumbnailUrl": "https://graph.facebook.com/987654321/picture?type=square",
                    "pictureUrl": "https://graph.facebook.com/987654321/picture?type=large",
                    "source": {
                        "identifier": 987654321,
                        "access_token": {
                            "key": "A21C619251FB098250A15A69B20BEE6ED6835149CE1496D78A674F11B0920F9FA21C619251FB098250A15A69B20BEE6ED6835149CE1496D78A674F11B0920F9F"
                        }
                    }
                }
            ]
        }
    }
}
}

MainActivity.java

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.MainActivity2">

    <android.support.v4.view.ViewPager

        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"  />

</RelativeLayout>

fragment_one.xml

public class MainActivity extends FragmentActivity {

    MyPageAdapter pageAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_activity2);
        List<Fragment> fragments = getFragments();
        pageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments);
        ViewPager pager = (ViewPager)findViewById(R.id.viewpager);
        pager.setAdapter(pageAdapter);

    }

    private List<Fragment> getFragments(){

        List<Fragment> fList = new ArrayList<Fragment>();


        fList.add(new Fragment1());
        fList.add(new Fragment2());

        return fList;

    }



    class MyPageAdapter extends FragmentPagerAdapter {

        private List<Fragment> fragments;

        public MyPageAdapter(FragmentManager fm, List<Fragment> fragments) {
            super(fm);
            this.fragments = fragments;

        }

        @Override

        public Fragment getItem(int position) {
            return this.fragments.get(position);
        }


        @Override

        public int getCount() {
            return this.fragments.size();
        }

    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        for (Fragment fragment : getSupportFragmentManager().getFragments()) {
            fragment.onActivityResult(requestCode, resultCode, data);
        }
    }


}

Fragment_One.java

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_left_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


                <TextView
                    android:id="@+id/select"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_above="@+id/me"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="10dp"
                    android:text="First Page"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@android:color/white" />


</RelativeLayout>

fragment_two.xml

public class Fragment_One extends android.support.v4.app.Fragment {


    @Override

    public View onCreateView(LayoutInflater inflater, ViewGroup container,

                             Bundle savedInstanceState) {

        View v = inflater.inflate(R.layout.fragment_one, container, false);


        return v;

    }

}

Fragment_two.java

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_left_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


                <TextView
                    android:id="@+id/select"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_above="@+id/me"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="10dp"
                    android:text="Second Page"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@android:color/white" />


</RelativeLayout>