2

首先我的英语不太好。但我会尽量理解我对你们的看法。我正在制作应用程序,其中我使用滚动视图,并在其中使用 API xml 的许多其他布局以及查看寻呼机。您可以在下面看到

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

下面是我的代码

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

        }

    }

}

所以我想滚动我的整个视图,并且在 viewpager 下方滚动时应该坚持使用工具栏。在 xml 中,您可以在滚动视图的末尾看到我的 viewpager 棒。没有上下运动。我想向上滚动并坚持使用工具栏,而不是向下滚动到它的位置。我怎样才能做到这一点。我也按照下面的链接进行了许多更改,但这对我没有帮助。最后我将代码清理到原始位置。 https://github.com/kmshack/Android-ParallaxHeaderViewPager http://architects.dzone.com/articles/how-make-google-plus-profile

谢谢

4

0 回答 0