samedi 27 juin 2015

Creating Vertical ScrollView inside ViewPager

I am trying to add a scrollView inside my ViewPager so I can scroll left and right as well as down if the page becomes full. As of now, I am dynamically adding views to my ViewPager:

Fragment Page in ViewPager:

ScrollView is not being inserted since i must remove the parent view.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mainView = View.inflate(getActivity(), R.layout.fragment_profile_personal_records, null);
    LinearLayout mainLayout = (LinearLayout) mainView.findViewById(R.id.layoutPR);
    ScrollView scrollView = new ScrollView(getActivity());
    scrollView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    for(int i = 0; i < 3; i++){
        LinearLayout rowLayout = (LinearLayout) mainView.inflate(getActivity(), R.layout.row_personal_records, null);
        mainLayout.addView(rowLayout);
    }
    scrollView.addView(mainLayout, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    return scrollView;
}

XML for Fragment:`

    <LinearLayout
    xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/layoutPR"
    android:orientation="vertical"
    tools:context="test.test.test.fragment">
</LinearLayout>

Container that contains viewPager:

   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_below="@id/mainLayout">

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/vpPager"
        android:scrollbars="vertical">

        <android.support.v4.view.PagerTabStrip
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/pagerHeader"
            android:layout_gravity="top"
            android:paddingBottom="5dp"
            android:textColor="#000000"
            android:paddingTop="5dp">
        </android.support.v4.view.PagerTabStrip>

    </android.support.v4.view.ViewPager>

</LinearLayout>

I have looked on the internet for answers but haven't come across anything that will insert a vertical scrollbar inside a viewPager that the view inside is created dynamically/programitcally and without xml

Aucun commentaire:

Enregistrer un commentaire