How can i scroll my whole view pager and stick to toolBar in Fragment Android?

489 views Asked by At

First of all my English is not too good. But i will try to understand my point to you people. I am making app in which i used scroll view and inside it many other layout with API xml's and also view pager.You can see below

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
        xmlns:custom="http://schemas.android.com/apk/res-auto"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context="com.iptikarpromotion.activity.LoaderActivity" >

        <ScrollView
            android:id="@+id/scrollview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@color/background_color" >

            <LinearLayout
                android:id="@+id/layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <com.daimajia.slider.library.SliderLayout
                    android:id="@+id/slider"
                    android:layout_width="match_parent"
                    android:layout_height="155dp"
                    custom:auto_cycle="true"
                    custom:indicator_visibility="visible"
                    custom:pager_animation="Accordion"
                    custom:pager_animation_span="1100" />

                <com.daimajia.slider.library.Indicators.PagerIndicator
                    android:id="@+id/custom_indicator"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:layout_marginBottom="20dp"
                    android:gravity="center"
                    custom:selected_color="@color/primary"
                    custom:selected_drawable="@drawable/ic_launcher"
                    custom:selected_height="6dp"
                    custom:selected_padding_left="6dp"
                    custom:selected_padding_right="6dp"
                    custom:selected_width="6dp"
                    custom:shape="oval"
                    custom:unselected_color="#55333333"
                    custom:unselected_height="6dp"
                    custom:unselected_padding_left="2dp"
                    custom:unselected_padding_right="2dp"
                    custom:unselected_width="6dp" />

                <com.daimajia.slider.library.Indicators.PagerIndicator
                    android:id="@+id/custom_indicator2"
                    style="@style/AndroidImageSlider_Corner_Oval_Orange"
                    android:layout_marginBottom="20dp" />
                   <--! Many other Linear and RelativeLayout is used here-->
                    <!-- For Viewpager -->
                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginTop="15dp" >
                        <TextView
                            android:id="@+id/textView3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentLeft="true"
                            android:layout_alignParentTop="true"
                            android:text="@string/quickly"
                            android:textColor="@color/current_deals_color"
                            android:textSize="15sp" >
                        </TextView>
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentLeft="true"
                            android:layout_below="@+id/textView3"
                            android:layout_marginTop="-3dp"
                            android:text="@string/sub_quickly"                              android:textColor="@color/all_categories_sub_title_color"
                            android:textSize="10sp"
                            android:textStyle="italic" />
                    </RelativeLayout>
                    <LinearLayout
                        android:id="@+id/rootContainer"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginTop="5dp"
                        android:orientation="vertical" >

                        <com.astuetz.PagerSlidingTabStrip
                            android:id="@+id/sliding_tabs"
                            style="@style/PagerTabStripText"
                            android:layout_width="match_parent"
                            android:layout_height="40dp"
                            android:layout_below="@+id/my_awesome_toolbar"
                            android:background="@drawable/bg_quickly_pick"
                            android:paddingBottom="3sp"
                            android:textSize="10sp"
                            app:pstsDividerColor="@android:color/transparent"
                            app:pstsIndicatorColor="@color/indicator_color"
                            app:pstsIndicatorHeight="3dp"
                            app:pstsTabPaddingLeftRight="15dip"
                            app:pstsUnderlineColor="@android:color/transparent" />

                        <android.support.v4.view.ViewPager
                             xmlns:android="http://schemas.android.com/apk/res/android"
                            android:id="@+id/pager"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" >
                        </android.support.v4.view.ViewPager>
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
        </ScrollView>
    </RelativeLayout>

And here id my code below

public class FragmentHome extends Fragment implements  ViewPager.OnPageChangeListener {

    private ViewPager viewPager;
    private TabPagerAdapter PagerAdapter;
    private static int pageIndexd; 
    private PagerSlidingTabStrip pagerSlidingTabStrip;
    LinearLayout ll_jewellery = null;
    private SliderLayout mDemoSlider;
    ScrollView scrollView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_home_layout, null);

        scrollView = (ScrollView)rootView.findViewById(R.id.scrollview);
        viewPager = (ViewPager) rootView.findViewById(R.id.pager);
        rootView.findViewById(R.id.layout);
        pagerSlidingTabStrip = (PagerSlidingTabStrip) rootView.findViewById(R.id.sliding_tabs);


        mDemoSlider = (SliderLayout)rootView.findViewById(R.id.slider);
        imageSlider();
        ll_jewellery = (LinearLayout)rootView.findViewById(R.id.ll_jewellery);
        CategoryLayoutClikListener categoryLayoutClikListener = new CategoryLayoutClikListener();
        ll_jewellery.setOnClickListener(categoryLayoutClikListener);

        viewPager.setOffscreenPageLimit(1);
        pageIndexd = viewPager.getCurrentItem();
        viewPager.setCurrentItem(pageIndexd);
        FragmentManager fm = getFragmentManager();

        PagerAdapter = new TabPagerAdapter(fm);
        setAdapter();

        return rootView;
    }

    @Override
    public void onPageScrollStateChanged(int arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onPageScrolled(int arg0, float arg1, int arg2) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onPageSelected(int position) {


    }



    private void imageSlider(){

         HashMap<String,String> url_maps = new HashMap<String, String>();

            url_maps.put("Hannibal", "http://static2.hypable.com/wp-content/uploads/2013/12/hannibal-season-2-release-date.jpg");
            url_maps.put("Big Bang Theory", "http://tvfiles.alphacoders.com/100/hdclearart-10.png");
            url_maps.put("House of Cards", "http://cdn3.nflximg.net/images/3093/2043093.jpg");
            url_maps.put("Game of Thrones", "http://images.boomsbeat.com/data/images/full/19640/game-of-thrones-season-4-jpg.jpg");

        for(String name : url_maps.keySet()){
            TextSliderView textSliderView = new TextSliderView(getActivity());
            // initialize a SliderLayout
            textSliderView.description(name).image(url_maps.get(name)).setScaleType(BaseSliderView.ScaleType.Fit);
            //.setOnSliderClickListener(this);

            //add your extra information
            textSliderView.getBundle().putString("extra",name);

           mDemoSlider.addSlider(textSliderView);
        }
        mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Default);
        mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
        mDemoSlider.setCustomAnimation(new DescriptionAnimation());
        mDemoSlider.setDuration(4000);
    }



    private void setAdapter() {

        viewPager.setAdapter(PagerAdapter);
        pagerSlidingTabStrip.setViewPager(viewPager);

    }

    private class CategoryLayoutClikListener implements OnClickListener {

        @Override
        public void onClick(View v) {

        }

    }

}

So i want to scroll my whole view, and on scroll below viewpager should be stick with toolbar. In xml you can see my viewpager stick below on end of scroll view. no movement up and down. i want to scroll up and stick with toolbar and than scroll down to its position. How can i achieve this. I follow this below link too and make many many changes but it doesnt help me.At the end i clean my code to original position. https://github.com/kmshack/Android-ParallaxHeaderViewPager http://architects.dzone.com/articles/how-make-google-plus-profile

Thanks

0

There are 0 answers