0

i am using slidingtablayout and slidingtabstrip, i have 5 tabs but there is one large text like RESTAURANT it is not visible fully.. and if i changed the other tabstext to largetext it is working fine and scrolling even..but not in the first case.enter image description here i want this.. but with above text on tabsenter image description here

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.rajdeepsingh.newlistview_module.Search">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="#ffffff"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="2"
            >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:id="@+id/navbut"
            android:background="@drawable/arrow"
            android:layout_margin="5dp"

            />

        <com.example.rajdeepsingh.newlistview_module.SlidingTabLayout1
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            />
        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"

            >

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/roundedcorneredittext"
            android:layout_margin="16dp"
            android:drawableLeft="@drawable/search01"
            android:drawableStart="@drawable/search01"
            android:id="@+id/searchedittext"
            android:hint="Brands, Restaurant, Shops "
            android:textColorHint="#bdbdbd"
            android:typeface="serif"

            />
        </LinearLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@android:color/white" />


    </LinearLayout>






</LinearLayout>
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
Aman Verma
  • 3,155
  • 7
  • 30
  • 60

4 Answers4

3

Please Check with this line in your Activity

slidingTabLayout.setDistributeEvenly(true);

change to false

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
1

@Aman Verma

Whats your Fault

  1. At first Start your Imageview Tag <ImageView
  2. Set slidingTabsObj.setDistributeEvenly(false); // Yes: To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width

SlidingTabLayout to fit the screen

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

You can use below code to expand your text in tabs.

SlidingTabStrip tabs = (SlidingTabStrip)rootView.findViewById(R.id.tabs);
tabs.setShouldExpand(true); 

Hope it helps.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47
0

With in your SlidingTabLayout1, Just replace below two methods and then check it.

/**
 * Create a default view to be used for mTabs. This is called if a custom tab
 * view is not set via {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(
            android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources()
            .getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate
            // it
            tabView = LayoutInflater.from(getContext()).inflate(
                    mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView
                    .findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView
                    .getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }

        tabTitleView.setTextColor(getResources().getColorStateList(
                R.color.selector));
        tabTitleView.setTextSize(14);

    }

}

Let me know if this update does not resolve your issue.

halfer
  • 19,824
  • 17
  • 99
  • 186
Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188