astuetz / PagerSlidingTabStrip

An interactive indicator to navigate between the different pages of a ViewPager
139 stars 44 forks source link

Inflating a customView in Tabs #262

Open anshul90 opened 8 years ago

anshul90 commented 8 years ago

I'm trying to replace title of Tabs with icons + titles

for (int i = 0; i < mAdapter.getCount(); i++) { View tabView = mAdapter.getCustomeView(getActivity(), i);;

    tabView = LayoutInflater.from(getContext()).inflate(R.layout.custom_tab_view, myTabLayout,
            false);
    String title_arr[] = {"ADVISORY", "CALENDER", "TOP ADVISORS", "EXPERT VIEW"};
    int[] drawables = new int[]{R.drawable.advisory_normal, R.drawable.calender_normal, R.drawable.topadvisor_normal, R.drawable.expertview_normal};
    TextView mTextView = (TextView) tabView.findViewById(R.id.textView);
    ImageView mImageView = (ImageView) tabView.findViewById(R.id.imageView2);
    mImageView.setImageResource(drawables[i]);
    mTextView.setText(title_arr[i]);
    myTabLayout.addView(tabView);
}

custom_layout

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:paddingBottom="@dimen/et_topPadding" android:paddingTop="@dimen/et_topPadding">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="3dp" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="@color/text_color"
        android:textSize="@dimen/custom_tab_tSize" />
</LinearLayout>

And getting error of Inflate Exception. Horizontal ScrollView can host only one child. How can I remove Scroll View without adding that class in my code?

dabaooline commented 7 years ago

I meet the same problem. Do you have been fixed it?

anshul90 commented 7 years ago

I used Android's TabLayout and made it scroll able.