-6

How to implement this type of animation with sliding effect and color transition in android. (IOS like sliding controller). Thanks in advance.

enter image description here

enter image description here

Asmin P
  • 1
  • 1

1 Answers1

0

try the my sample code

activity_main_activity2

<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>

MainActivity.java

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.xml

<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_One.java

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.xml

<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>

Fragment_two.java

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


    @Override

    public View onCreateView(LayoutInflater inflater, ViewGroup container,

                             Bundle savedInstanceState) {

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


        return v;

    }

}
Gaurav Rawal
  • 218
  • 1
  • 6